litesoft
@ 947
litesoft / trunk / Java / core / Server / src / org / litesoft / peertopeer / nonpublic / peermanagement / P2PConstants.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.peertopeer.nonpublic.peermanagement; public interface P2PConstants { public static final long MILLISEC_TIME_OUT_WAITING_FOR_PEER = 1000; public static final int DISCOVERY_PORT = 0xBEEF; public static final int BASE_SERVER_PORT = DISCOVERY_PORT + 1; public static final byte[] BROADCAST_PREFIX = {'L', 'S', 'P', 'D', '1', ':'}; public static final int MINIMUM_BROADCAST_MESSAGE_LENGTH = BROADCAST_PREFIX.length + 10; /* P2P approach: Broadcast our (Pi) existence (overall packet size not to exceed 255 bytes) w/: Prefix ("LSPD") & Protocol Version ('1') & ':', Data (Java's String .getBytes() format; max length 249): Group Name/ID (trimmed & no ',') & ',', (>=2) Supported Group Protocol Version (trimmed & no ',') & ',', (>=1) Our Name/ID (trimmed & no ',') & ',', (>=2) Our Listening Server Port Number. (>=4) All the Peers (Pn) that receive the broadcast AND are interested in peering based on Group Name/ID: Connect (Opening R/W Streams) to the Pi's Server Port (all communication done via Java's Serialization mechanism ObjectOutputStream & ObjectInputStream) and either: Send a CantPeerDifferentGroupVersion w/ Our Name/ID & Supported Group Protocol Version Pi closes connection, and then either: Proceeds as if the Pn'th does not exist. or Shuts down as mixed versions are unacceptable! or Sends PeerList (possibly empty) of all 'other' known Group Peers. Each Peer in the list is represented by a PeerDefinition: Name, InetAddress, & Port For each Peer in the List just recieved that is currently unknown, it is added to the Known List & the Contact Pending List. For each Peer in the Contact Pending List, a connection is established and the Known List is send to it. When 1 second (is this long enough) has passed with no new Peers connecting to pI, then assume that no more are comming. If there are NO Pn(s), then proceed on the assumption that we are alone or first! Each message from a Pn will be a Serializable and if it is NOT a PeerList or a CantPeerDifferentGroupVersion, then each MessageFromPeerHandler will be asked to handle the Serializable, as soon as one has handled the Serializable, then the Serializable has been handled and no more MessageFromPeerHandler's will be called. */ } |