예제 #1
0
 internal RemotePeer(P2PGroup group, ProudSession session, Crypt crypt)
 {
     Group            = group;
     HostId           = session.HostId;
     Crypt            = crypt;
     ConnectionStates = new ConcurrentDictionary <uint, P2PConnectionState>();
     Session          = session;
 }
예제 #2
0
        public void AddSession(TKey key, ProudSession session)
        {
            if (!_sessions.TryAdd(key, session))
            {
                throw new ProudException($"Session {key} is already registered");
            }

            _schedulerService.Execute(
                (This, s) => ((SessionManager <TKey>)This).OnAdded((ProudSession)s),
                this, session
                );
        }
예제 #3
0
        public void Send(ProudSession session, CoreMessage message)
        {
            using (var ms = new PooledMemoryStream(_pipe.Service.ArrayPool))
                using (var w = new BinaryWriter(ms))
                {
                    var @out = _protocol.Serialize(session, message);
                    using (var ms2 = new PooledMemoryStream(_pipe.Service.ArrayPool))
                    {
                        @out.Serialize(ms2);
                        var segment = ms2.ToSegment();

                        w.Write((ushort)43981);
                        w.Write((ushort)0);
                        w.Write(segment.Count);
                        w.Write(0);
                        w.Write(0);
                        w.Write(segment.Array, segment.Offset, segment.Count);

                        segment = ms.ToSegment();
                        _socket.SendTo(segment.Array, segment.Offset, segment.Count, SocketFlags.None, session.UdpEndPoint);
                    }
                }
        }
예제 #4
0
 public ErrorEventArgs(ProudSession session, Exception exception)
 {
     Session   = session;
     Exception = exception;
 }
예제 #5
0
 protected virtual void OnDisconnected(ProudSession session)
 {
     Disconnected?.Invoke(this, session);
 }
예제 #6
0
 internal void AddSession(ProudSession session)
 {
     Configuration.Logger?.Debug("Adding new session {HostId}", session.HostId);
     _sessions[session.HostId] = session;
     OnConnected(session);
 }
예제 #7
0
 public SessionEventArgs(ProudSession session)
 {
     Session = session;
 }
예제 #8
0
 protected virtual void OnRemoved(ProudSession session)
 {
     Removed?.Invoke(this, new SessionEventArgs(session));
 }
예제 #9
0
 internal void RemoveSession(ProudSession session)
 {
     _sessions.Remove(session.HostId);
     SessionsByUdpId.Remove(session.UdpSessionId);
     OnDisconnected(session);
 }
예제 #10
0
 internal void AddSession(ProudSession session)
 {
     _sessions[session.HostId] = session;
     OnConnected(session);
 }