/* * Unifies all known data from the other Server. */ private void Synchronize(SyncMessage msg) { PoolDebug("Synchronizing with " + msg.ServerId); MergeServicesByType(msg.ServicesByType); MergeServicesByUid(msg.ServicesByUid); MergeServicesPerApplication(msg.ServicesPerApplication); MergeKnownServers(msg.KnownServers); }
//received rpc message had a ServerPool prefix, so will be treated as a ServerPool message from now on. private void ReceiveServerPoolMessage(MemoryStream stream) { ServerPoolMessageRPC poolMessageRpcType = (ServerPoolMessageRPC)stream.ReadByte(); switch (poolMessageRpcType) { case ServerPoolMessageRPC.RequestServerUid: { //PoolDebug("RequestServerUid firing"); Address myPublicRpcAddress = StreamUtil.Read<Address>(stream); //PoolDebug("RequestServerUid firing 0"); Address myPublicPubAddress = StreamUtil.Read<Address>(stream); //PoolDebug("RequestServerUid firing 1"); long newUid = NewServerUIDInPool(myPublicRpcAddress, myPublicPubAddress); //PoolDebug("RequestServerUid firing 2"); SyncMessage thisDataSyncMessage = new SyncMessage(); thisDataSyncMessage.KnownServers = _knownServers; thisDataSyncMessage.ServerId = _serverUid; thisDataSyncMessage.ServicesByType = _servicesByType; //PoolDebug("RequestServerUid firing 3"); thisDataSyncMessage.ServicesByUid = _servicesByUID; thisDataSyncMessage.ServicesPerApplication = _servicesPerApplication; MemoryStream sendStream = new MemoryStream(); //PoolDebug("RequestServerUid firing 4"); StreamUtil.Write(sendStream, newUid); StreamUtil.Write(sendStream, thisDataSyncMessage); //PoolDebug("RequestServerUid firing 5"); _rpcSocket.Send(sendStream.GetBuffer()); //PoolDebug("RequestServerUid fired 6"); } break; case ServerPoolMessageRPC.ReserveServerUid: { long proposal = StreamUtil.Read<long>(stream); bool ok = true; if (_serverUid == proposal || _knownServers.Where(x => (x.GlobalServerId == proposal)).Any() || _reservedServerUids.Contains(proposal)) ok = false; MemoryStream sendStream = new MemoryStream(); StreamUtil.Write(sendStream, ok); _rpcSocket.Send(sendStream.GetBuffer()); } break; case ServerPoolMessageRPC.AddServer: { ServerInfo si = StreamUtil.Read<ServerInfo>(stream); AddServerToServerPool(si); _rpcSocket.Send(); PoolDebug("Remote server joined pool"); } break; //SERVICE (a client) case ServerPoolMessageRPC.ReserveServiceUid: { ulong proposal = StreamUtil.Read<ulong>(stream); bool ok = true; if (_reservedApplicationUids.Contains(proposal)) ok = false; MemoryStream sendStream = new MemoryStream(); StreamUtil.Write(sendStream, ok); _rpcSocket.Send(sendStream.GetBuffer()); } break; } }