Exemplo n.º 1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="ownId">The ID of this server.</param>
 /// <param name="serverIPs">The dictionary with server IDs and IP endpoints, including this server. Do not make later
 /// changes to any of the IPEndPoint objects!</param>
 public TcpTransport(string ownId, IDictionary <string, IPEndPoint> serverIPs)
 {
     OwnId = ownId ?? throw new ArgumentNullException(nameof(ownId));
     if (serverIPs == null)
     {
         throw new ArgumentNullException(nameof(serverIPs));
     }
     LocalEndpoint = serverIPs[ownId];
     (ServerIPs, _clientConnections) = Shield.InTransaction(() =>
     {
         var ips     = new ShieldedDict <string, IPEndPoint>(serverIPs.Where(kvp => !StringComparer.InvariantCultureIgnoreCase.Equals(kvp.Key, ownId)));
         var clients = new ConcurrentDictionary <string, TcpClientConnection>(
             ips.Select(kvp => new KeyValuePair <string, TcpClientConnection>(kvp.Key, new TcpClientConnection(this, kvp.Value))));
         Shield.PreCommit(() => ips.TryGetValue("any", out var _) || true,
                          () => Shield.SyncSideEffect(UpdateClientConnections));
         return(ips, clients);
     });
 }