public bool Connect(LocationData location) { if (location.UserID == Network.Local.UserID && location.Source.ClientID == Network.Local.ClientID) { return(false); } ulong id = location.UserID ^ location.Source.ClientID; if (SessionMap.ContainsKey(id)) { return(SessionMap[id].Status != SessionStatus.Closed); } RudpSession session = new RudpSession(this, location.UserID, location.Source.ClientID, false); SessionMap[id] = session; session.Comm.AddAddress(new RudpAddress(new DhtAddress(location.IP, location.Source))); foreach (DhtAddress address in location.Proxies) { session.Comm.AddAddress(new RudpAddress(address)); } foreach (DhtAddress server in location.TunnelServers) { session.Comm.AddAddress(new RudpAddress(new DhtContact(location.Source, location.IP, location.TunnelClient, server))); } session.Connect(); return(true); }
public bool Connect(DhtClient client) { if (client.UserID == Network.Local.UserID && client.ClientID == Network.Local.ClientID) { return(false); } // sessionmap and socketmap both need to have the same # of entries // if a session is fin or closed, we need to wait for fins to complete before re-assigning entry if (SessionMap.ContainsKey(client.RoutingID)) { return(SessionMap[client.RoutingID].Status != SessionStatus.Closed); } RudpSession session = new RudpSession(this, client.UserID, client.ClientID, false); SessionMap[client.RoutingID] = session; if (Network.LightComm.Clients.ContainsKey(client.RoutingID)) { foreach (RudpAddress address in Network.LightComm.Clients[client.RoutingID].Addresses) { session.Comm.AddAddress(address); } } session.Connect(); return(true); // indicates that we will eventually notify caller with close, so caller can clean up }
public void RemoveSession(RudpSession session) { lock (SocketMap) if (SocketMap.ContainsKey(session.Comm.PeerID)) { SocketMap.Remove(session.Comm.PeerID); } SessionMap.Remove(session.RoutingID); }
public RudpSocket(RudpSession session, bool listening) { Session = session; Core = session.Core; Network = Session.Network; Bandwidth = new BandwidthLog(Core.RecordBandwidthSeconds); Listening = listening; PeerID = (ushort)Core.RndGen.Next(1, ushort.MaxValue); lock (Session.RudpControl.SocketMap) Session.RudpControl.SocketMap[PeerID] = this; }
public bool Contains(RudpSession rudp) { if (AllSessions.Contains(rudp.UserID)) { return(true); } if (!Sessions.ContainsKey(rudp.UserID)) { return(false); } if (Sessions[rudp.UserID].Contains(rudp.ClientID)) { return(true); } return(false); }
public void Add(RudpSession rudp) { Add(rudp.UserID, rudp.ClientID); }