Esempio n. 1
0
        /// <summary>
        /// Add a generic peer to the recording
        /// </summary>
        /// <param name="commLink">ICommunicator to record</param>
        /// <param name="dumpToFile">True if packets for this peer should be written to individual file</param>
        /// <param name="dumpFileExtension">Extension for the individual dump file</param>
        public bool AddPeer(ICommunicator commLink, bool dumpToFile, string dumpFileExtension = ".dump")
        {
            if (CurrentState == State.Recording)
            {
                return(false);
            }

            if (!socketListeners.ContainsKey(commLink.ID))
            {
                commLink.DataReadySyncEvent += DataReadyEventCallback;
                commLink.DataRateEvent      += OnDataRate;

                RecPeerInfo p = new RecPeerInfo()
                {
                    ID                = commLink.ID,
                    DumpToFile        = dumpToFile,
                    DumpFileExtension = dumpFileExtension,
                    commsLink         = commLink,
                    IP                = commLink.CommsUri.IP,
                    Port              = commLink.CommsUri.LocalPort
                };

                bool doneRight = socketListeners.TryAdd(commLink.ID, p) && _dataRate.TryAdd(commLink.ID, 0);
                return(doneRight);
            }

            return(false);
        }
Esempio n. 2
0
        public bool AddPeer(string ID, string ip, int port, bool dumpToFile, string netcard = "", string dumpFileExtension = ".dump")
        {
            // Check valid IP
            if (IPAddress.TryParse(ip, out IPAddress ipAddres) && !udpListeners.ContainsKey(ID))
            {
                UDPNETCommunicator <object> u = new UDPNETCommunicator <object>();
                u.Init(new ConnUri($"udp://{ip}::{netcard}:{port}"), false, ID, 0);
                u.DataReadyEvent += DataReadyEventCallback;
                u.DataRateEvent  += OnDataRate;

                RecPeerInfo p = new RecPeerInfo()
                {
                    ID                = ID,
                    DumpToFile        = dumpToFile,
                    DumpFileExtension = dumpFileExtension,
                    commsLink         = u,
                    IP                = ip,
                    Port              = port,
                    External          = false
                };

                udpListeners.Add(ID, p);
                _dataRate.Add(ID, 0);

                return(true);
            }

            return(false);
        }
Esempio n. 3
0
        /// <summary>
        /// Add a multicast peer to the recording
        /// </summary>
        /// <param name="ID">Given ID</param>
        /// <param name="ip">Multicast IP</param>
        /// <param name="port">Multicast destination port</param>
        /// <param name="dumpToFile">True if packets for this peer should be written to individual file</param>
        /// <param name="netcard">Not needed, will join multicast group in all interfaces</param>
        /// <param name="dumpFileExtension">Extension for the individual dump file</param>
        /// <returns>True if peer is added</returns>
        public bool AddPeer(string id, string ip, int port, bool dumpToFile, string netcard = "", string dumpFileExtension = ".dump")
        {
            if (CurrentState == State.Recording)
            {
                logger.Info($"Added Peer {id} - {ip}:{port} Failed. Recording ongoing");
                return(false);
            }

            // Check valid IP
            if (IPAddress.TryParse(ip, out IPAddress ipAddres) && !socketListeners.ContainsKey(id))
            {
                IPSocketCommunicator <object> u = new IPSocketCommunicator <object>();
                u.Init(new ConnUri($"udp://{ip}::{netcard}:{port}"), false, id, 0);
                u.DataReadySyncEvent += DataReadyEventCallback;
                u.DataRateEvent      += OnDataRate;

                RecPeerInfo p = new RecPeerInfo()
                {
                    ID                = id,
                    DumpToFile        = dumpToFile,
                    DumpFileExtension = dumpFileExtension,
                    commsLink         = u,
                    IP                = ip,
                    Port              = port
                };

                socketListeners.Add(id, p);
                _dataRate.Add(id, 0);

                logger.Info($"Added Peer {id} - {ip}:{port} Sucessful");
                return(true);
            }

            return(false);
        }
Esempio n. 4
0
        public void AddPeer(ICommunicator commLink, bool dumpToFile, string dumpFileExtension = ".dump")
        {
            if (!udpListeners.ContainsKey(commLink.ID))
            {
                commLink.DataReadyEvent += DataReadyEventCallback;
                commLink.DataRateEvent  += OnDataRate;

                RecPeerInfo p = new RecPeerInfo()
                {
                    ID                = commLink.ID,
                    DumpToFile        = dumpToFile,
                    DumpFileExtension = dumpFileExtension,
                    commsLink         = commLink,
                    IP                = commLink.CommsUri.IP,
                    Port              = commLink.CommsUri.LocalPort,
                    External          = true
                };

                udpListeners.Add(commLink.ID, p);
                _dataRate.Add(commLink.ID, 0);
            }
        }