コード例 #1
0
        public string ToString(LocalPeer localPeer)
        {
            var sb = new StringBuilder();

            sb.AppendFormat("{0}_{1}(", Type, RemotePeerId);
            foreach (var stream in Streams.Values)
            {
                sb.Append(stream.ToString());
                if (localPeer != null)
                {
                    sb.AppendFormat(" hr/c: {0:0.0}sec ago", (localPeer.DateTimeNowUtc - (stream.LastTimeReceivedAccepted ?? stream.Created)).TotalSeconds);
                }
                sb.Append(";");
            }

            sb.Append(")");
            if (LibraryVersion != null)
            {
                sb.AppendFormat("lib:{0:yyMMdd-HH:mm}", LibraryVersion);
            }
            if (ProtocolVersion != null)
            {
                sb.AppendFormat("p:{0}", ProtocolVersion);
            }


            return(sb.ToString());
        }
コード例 #2
0
 /// <param name="remotePeerId">null for 'pending' peers</param>
 internal ConnectedPeer(LocalPeer localPeer, PeerId remotePeerId, ConnectedPeerType type, IPAddress remoteIp)
 {
     RemoteIp     = remoteIp.ToString();
     Type         = type;
     RemotePeerId = remotePeerId;
     _localPeer   = localPeer;
     Extensions   = localPeer.Configuration.Extensions.ToDictionary(ext => ext, ext => ext.OnConnectedPeer(this));
 }
コード例 #3
0
 internal ConnectedPeerStream(LocalPeer localPeer, ConnectedPeer connectedPeer, StreamId streamId,
                              IPEndPoint remoteEP, SocketWithReceiver socket)
 {
     _localPeer     = localPeer;
     Created        = localPeer.DateTimeNowUtc;
     StreamId       = streamId;
     RemoteEndPoint = remoteEP;
     Socket         = socket;
     Extensions     = connectedPeer.Extensions.ToDictionary(ext => ext.Key, ext => ext.Value.OnConnectedPeerStream(this));
 }
コード例 #4
0
        public SocketWithReceiver(LocalPeer localPeer, UdpClient udpSocket)
        {
            _localPeer    = localPeer;
            _actionsQueue = new ActionsQueue(exc => _localPeer.HandleException(LogModules.GeneralManager, exc), new ExecutionTimeStatsCollector(() => localPeer.DateTimeNow));
            UdpSocket     = udpSocket;

            _thread          = new Thread(ThreadEntry);
            _thread.Name     = "receiver " + LocalEndPointString;
            _thread.Priority = ThreadPriority.Highest;
            _thread.Start();
        }
コード例 #5
0
        public SocketWithReceiver(LocalPeer localPeer, UdpClient udpSocket)
        {
            _localPeer    = localPeer;
            _actionsQueue = new ActionsQueue(exc => _localPeer.HandleException(LogModules.GeneralManager, exc));
            UdpSocket     = udpSocket;

            _thread          = new Thread(ThreadEntry);
            _thread.Name     = LocalEndPointString;
            _thread.Priority = ThreadPriority.Highest;
            _thread.Start();
        }
コード例 #6
0
        public LocalPeer(LocalPeerConfiguration configuration)
        {
            if (configuration.VisionChannel == null)
            {
                throw new ArgumentNullException(nameof(configuration.VisionChannel));
            }
            if (configuration.Extensions == null)
            {
                configuration.Extensions = new ILocalPeerExtension[0];
            }
            VisionChannel         = configuration.VisionChannel;
            VisionChannelSourceId = configuration.VisionChannelSourceId;
            Configuration         = configuration;
            if (configuration.RoleAsUser)
            { // client
                if (configuration.RoleAsSharedPassive || configuration.RoleAsCoordinator)
                {
                    throw new ArgumentException(nameof(configuration.RoleAsUser));
                }
                if (configuration.Coordinators == null || configuration.Coordinators.Length < 1)
                {
                    throw new ArgumentException("Please enter coordinator server(s) details: IP addresses and ports");
                }
                //  if (configuration.SubtUserTargetBandwidthBps == null) throw new ArgumentException(nameof(configuration.SubtUserTargetBandwidthBps));
            }
            else if (configuration.RoleAsCoordinator)
            { // server
                if (configuration.LocalUdpPortRangeStart == null)
                {
                    throw new ArgumentException(nameof(configuration.LocalUdpPortRangeStart));
                }
            }
            else if (configuration.RoleAsSharedPassive)
            {
            }
            else
            {
                throw new Exception("no roles");
            }

            if (configuration.SocketsCount <= 0 || configuration.SocketsCount > 2000)
            {
                throw new ArgumentException(nameof(configuration.SocketsCount));
            }

            ExtensionsById = configuration.Extensions.ToDictionary(ext => ext.ExtensionId, ext => ext);
            Initialize();
            if (_instance != null)
            {
                throw new InvalidOperationException();
            }
            _instance = this;
        }
コード例 #7
0
ファイル: Manager.cs プロジェクト: ciprianp/dcomms
        public Manager(LocalPeer localPeer)
        {
            _localPeer        = localPeer;
            localPeer.Manager = this;
            _actionsQueue     = new ActionsQueue(exc => _localPeer.HandleException(LogModules.GeneralManager, exc), new ExecutionTimeStatsCollector(() => localPeer.DateTimeNow));

            if (_localPeer.Configuration.Coordinators != null)
            {
                // connect to coordinator peers
                foreach (var serverEP in _localPeer.Configuration.Coordinators)
                {
                    AddToPendingPeers(ConnectedPeerType.toConfiguredServer, serverEP, GetSocketForNewOutgoingStream());
                }
            }

            _thread      = new Thread(ThreadEntry);
            _thread.Name = "manager thread";
            _thread.Start();
        }
コード例 #8
0
        public void Dispose(bool currentManagerWillDisposeItselfAfterThisProcedure)
        {
            foreach (var extension in ExtensionsById.Values)
            {
                extension.DestroyWithLocalPeer();
            }
            if (!currentManagerWillDisposeItselfAfterThisProcedure)
            {
                Manager.Dispose();
            }
            Manager = null;
            foreach (var receiver in Receivers)
            {
                receiver.Dispose();
            }
            Receivers = null;

            _instance = null;
        }
コード例 #9
0
        /// <summary>
        /// begins scraping asynchronously
        /// </summary>
        public IpLocationScraper(string localPublicIp, LocalPeer localPeer)
        {
            _localPeer     = localPeer;
            _localPublicIp = localPublicIp;
#if DEBUG
            if (_localPublicIp == "127.0.0.1")
            {
                _localPublicIp = "8.8.8.8";
            }
#endif
            try
            {
                SendHttpRequestsAsync();
            }
            catch (Exception exc)
            {
                localPeer.HandleException(LogModules.IpLocationScraper, exc);
            }
        }
コード例 #10
0
 /// <param name="remotePeerId">null for 'pending' peers</param>
 internal ConnectedPeer(LocalPeer localPeer, PeerId remotePeerId)
 {
     RemotePeerId = remotePeerId;
     _localPeer   = localPeer;
     Extensions   = localPeer.Configuration.Extensions.ToDictionary(ext => ext, ext => ext.OnConnectedPeer(this));
 }