public void sendAndReceiveHello(Peer neighbor, Ring ring) { byte[] message = new byte[Constants.WRITEBUFFSIZE]; byte[] reply = new byte[Constants.READBUFFSIZE]; MemoryStream stream; try { User user = User.getInstance(); BinaryFormatter serializer = new BinaryFormatter(); stream = new MemoryStream(message); NetLib.insertEntropyHeader(serializer, stream); RingInfo ringInfo = user.findRingInfo(ring.ringID); serializer.Serialize(stream, Constants.MessageTypes.MSG_HELLO); serializer.Serialize(stream, ring.ringID); serializer.Serialize(stream, ringInfo.token); serializer.Serialize(stream, new Peer(user.node, user.publicUserInfo, ringInfo.IE)); reply = NetLib.communicate(neighbor.node.syncCommunicationPoint, message, true); Debug.Assert(reply != null, "Neighbor did not reply to Hello"); BinaryFormatter deserializer = new BinaryFormatter(); stream = new MemoryStream(reply); NetLib.bypassEntropyHeader(deserializer, stream); Constants.MessageTypes replyMsg = (Constants.MessageTypes)deserializer.Deserialize(stream); switch(replyMsg) { case Constants.MessageTypes.MSG_HELLO: uint ringID = (uint)deserializer.Deserialize(stream); if(ringID != ring.ringID) return; ulong token = (ulong)deserializer.Deserialize(stream); Peer peer = (Peer)deserializer.Deserialize(stream); IPEndPoint neighborIPEndPoint = peer.node.syncCommunicationPoint; if(!neighborIPEndPoint.Address.Equals(neighbor.node.syncCommunicationPoint.Address)) //REVISIT: alert security system return; neighbor.node.syncCommunicationPoint = neighborIPEndPoint; neighbor.node.asyncCommunicationPoint = peer.node.asyncCommunicationPoint; neighbor.IE = peer.IE; break; case Constants.MessageTypes.MSG_DISCONNECT: neighbor.IE = null; break; default: neighbor.IE = null; break; } } catch (Exception e) { int x = 2; } }
public RingInfo(Ring __ring, string __userName, string __password) { ring = __ring; userName = __userName; password = System.Text.Encoding.ASCII.GetBytes(__password); neighbors = new ArrayList(Constants.MIN_NUM_NEIGHBORS); }
public ServerRingInfo(Ring __ring, ClientManager __ringClientManager, AccountsManager __ringAccountsManager, PeerManager __ringPeerManager, ServerPolicyManager __serverPolicyManager) { ring = __ring; ringClientManager = __ringClientManager; ringAccountsManager = __ringAccountsManager; ringPeerManager = __ringPeerManager; serverPolicyManager = __serverPolicyManager; nextSessionID = 1; }
private void getRingNeighbors(IPEndPoint lord, Ring ring) { byte[] message = new byte[Constants.WRITEBUFFSIZE]; byte[] reply = new byte[Constants.READBUFFSIZE]; MemoryStream stream; try { User user = User.getInstance(); BinaryFormatter serializer = new BinaryFormatter(); stream = new MemoryStream(message); NetLib.insertEntropyHeader(serializer, stream); serializer.Serialize(stream, Constants.MessageTypes.MSG_RINGLOGIN); serializer.Serialize(stream, ring.ringID); RingInfo ringInfo = user.findRingInfo(ring.ringID); serializer.Serialize(stream, ringInfo.userName); serializer.Serialize(stream, SecurityLib.encrypt(ringInfo.password)); serializer.Serialize(stream, user.node.syncCommunicationPoint); serializer.Serialize(stream, ringInfo.IE); reply = NetLib.communicate(lord, message, true); BinaryFormatter deserializer = new BinaryFormatter(); stream = new MemoryStream(reply); NetLib.bypassEntropyHeader(deserializer, stream); Constants.MessageTypes replyMsg = (Constants.MessageTypes)deserializer.Deserialize(stream); Constants.QueryHandlerType howToHandleQuery; switch(replyMsg) { case Constants.MessageTypes.MSG_RINGNEIGHBORS: ringInfo.token = (ulong)serializer.Deserialize(stream); howToHandleQuery = (Constants.QueryHandlerType)serializer.Deserialize(stream); ringInfo.queryServer = (IPEndPoint)serializer.Deserialize(stream); switch(howToHandleQuery) { case Constants.QueryHandlerType.SERVER_FORM_QUERY: ringInfo.searchRing = new RingInfo.ringSearcher(ringInfo.searchRingServerFormQuery); break; case Constants.QueryHandlerType.SERVER_RESOLVE_QUERY: ringInfo.searchRing = new RingInfo.ringSearcher(ringInfo.searchRingServerResolveQuery); break; case Constants.QueryHandlerType.DISTRIBUTED_PEER_QUERY: ringInfo.searchRing = new RingInfo.ringSearcher(ringInfo.searchRingDistributedP2PEntropy); break; } Peer[] neighbors = (Peer[])deserializer.Deserialize(stream); foreach (Peer neighbor in neighbors) ringInfo.neighbors.Add(new Neighbor(neighbor, new NeighborProxy())); break; default: ringInfo.neighbors = null; break; } } catch (Exception e) { int x = 2; } }