|
@@ -19,8 +19,7 @@ |
19 |
19 |
|
private String mOurName, mAppGroupID, mAppGroupVersion, mMessagePrefixFilter; |
20 |
20 |
|
private AppGroupVersionCompatibilityChecker mCompatibilityChecker; |
21 |
21 |
|
|
22 |
|
- |
public BroadcastMessageManager( String pOurName, String pAppGroupID, String pAppGroupVersion, |
23 |
|
- |
AppGroupVersionCompatibilityChecker pCompatibilityChecker ) |
|
22 |
+ |
public BroadcastMessageManager( String pOurName, String pAppGroupID, String pAppGroupVersion, AppGroupVersionCompatibilityChecker pCompatibilityChecker ) |
24 |
23 |
|
{ |
25 |
24 |
|
mOurName = assertNotEmptyAndNoCommas( "OurName", pOurName ); |
26 |
25 |
|
mAppGroupID = assertNotEmptyAndNoCommas( "AppGroupID", pAppGroupID ); |
|
@@ -38,14 +37,11 @@ |
38 |
37 |
|
{ |
39 |
38 |
|
if ( mOurServer != null ) |
40 |
39 |
|
{ |
41 |
|
- |
throw new IllegalStateException( |
42 |
|
- |
"BroadcastMessageManager has already joined (or attempted to join) Group: " + |
43 |
|
- |
mAppGroupID ); |
|
40 |
+ |
throw new IllegalStateException( "BroadcastMessageManager has already joined (or attempted to join) Group: " + mAppGroupID ); |
44 |
41 |
|
} |
45 |
42 |
|
} |
46 |
43 |
|
|
47 |
|
- |
public synchronized void joinGroup( int pServerPort, |
48 |
|
- |
PeerConnectionHandlerFactory pConnectionHandlerFactory ) |
|
44 |
+ |
public synchronized void joinGroup( int pServerPort, PeerConnectionHandlerFactory pConnectionHandlerFactory ) |
49 |
45 |
|
throws IOException |
50 |
46 |
|
{ |
51 |
47 |
|
P2Putils.validatePort( pServerPort ); |
|
@@ -84,8 +80,7 @@ |
84 |
80 |
|
} |
85 |
81 |
|
} |
86 |
82 |
|
|
87 |
|
- |
private void processAnnounceMessage( String pMessage, InetAddress pInetAddress, |
88 |
|
- |
PeerConnectionHandlerFactory pConnectionHandlerFactory ) |
|
83 |
+ |
private void processAnnounceMessage( String pMessage, InetAddress pInetAddress, PeerConnectionHandlerFactory pConnectionHandlerFactory ) |
89 |
84 |
|
{ |
90 |
85 |
|
if ( !pMessage.startsWith( mMessagePrefixFilter ) ) |
91 |
86 |
|
{ |
|
@@ -99,19 +94,15 @@ |
99 |
94 |
|
String thierAppGroupVersion = pMessage.substring( cAt1 + 1, cAt2 ).trim(); |
100 |
95 |
|
String thierName = pMessage.substring( cAt2 + 1, cAt3 ).trim(); |
101 |
96 |
|
String thierServerPort = pMessage.substring( cAt3 + 1 ).trim(); |
102 |
|
- |
if ( (thierAppGroupVersion.length() != 0) && (thierName.length() != 0) && |
103 |
|
- |
(thierServerPort.length() != 0) ) |
|
97 |
+ |
if ( (thierAppGroupVersion.length() != 0) && (thierName.length() != 0) && (thierServerPort.length() != 0) ) |
104 |
98 |
|
{ |
105 |
99 |
|
int zPort = parseServerPort( thierServerPort ); |
106 |
100 |
|
if ( zPort != 0 ) |
107 |
101 |
|
{ |
108 |
102 |
|
PeerDefinition zNewPeerDef = new PeerDefinition( thierName, pInetAddress, zPort ); |
109 |
|
- |
if ( !mAppGroupVersion.equals( thierAppGroupVersion ) && ( |
110 |
|
- |
(mCompatibilityChecker == null) || |
111 |
|
- |
!mCompatibilityChecker.areCompatibile( mAppGroupVersion, thierAppGroupVersion )) ) |
|
103 |
+ |
if ( !mAppGroupVersion.equals( thierAppGroupVersion ) && ((mCompatibilityChecker == null) || !mCompatibilityChecker.areCompatibile( mAppGroupVersion, thierAppGroupVersion )) ) |
112 |
104 |
|
{ |
113 |
|
- |
pConnectionHandlerFactory.handleAnnouncedPeerWithIncompatibleAppGroupVersions( |
114 |
|
- |
zNewPeerDef, mOurName, mAppGroupVersion, thierAppGroupVersion ); |
|
105 |
+ |
pConnectionHandlerFactory.handleAnnouncedPeerWithIncompatibleAppGroupVersions( zNewPeerDef, mOurName, mAppGroupVersion, thierAppGroupVersion ); |
115 |
106 |
|
} |
116 |
107 |
|
else |
117 |
108 |
|
{ |
|
@@ -127,8 +118,7 @@ |
127 |
118 |
|
private byte[] createAnnouceMessage( int pServerPort ) |
128 |
119 |
|
throws UnsupportedEncodingException |
129 |
120 |
|
{ |
130 |
|
- |
return createAnnouceMessage( |
131 |
|
- |
mAppGroupID + "," + mAppGroupVersion + "," + mOurName + "," + pServerPort ); |
|
121 |
+ |
return createAnnouceMessage( mAppGroupID + "," + mAppGroupVersion + "," + mOurName + "," + pServerPort ); |
132 |
122 |
|
} |
133 |
123 |
|
|
134 |
124 |
|
private static byte[] createAnnouceMessage( String pMessage ) |
|
@@ -180,8 +170,7 @@ |
180 |
170 |
|
String zMessage = null; |
181 |
171 |
|
try |
182 |
172 |
|
{ |
183 |
|
- |
zMessage = new String( zData, zEncodedStringStartsAt, zDataLength - zEncodedStringStartsAt, |
184 |
|
- |
FileUtils.UTF_8 ); |
|
173 |
+ |
zMessage = new String( zData, zEncodedStringStartsAt, zDataLength - zEncodedStringStartsAt, FileUtils.UTF_8 ); |
185 |
174 |
|
} |
186 |
175 |
|
catch ( UnsupportedEncodingException e ) |
187 |
176 |
|
{ |