public bool RemoveReplayAddress(string _id, out PlayPeerInfo pOriginal) { pOriginal = null; if (CurrentState != State.Stoped) { return(false); } int hashedID = HelperTools.GetDeterministicHashCode(_id); if (udpSenders.TryGetValue(hashedID, out PlayPeerInfo p)) { var original = udpSendersOriginal[hashedID]; p.IP = original.IP; p.Port = original.Port; p.NIC = original.NIC; pOriginal = original; return(true); } return(false); }
public bool AddReplayAddress(string _ID, string _dstIP, int _dstPort, string _nic) { if (CurrentState != State.Stoped) { return(false); } if (_dstIP is null || _dstPort <= 0 || _dstPort > 65535) { return(false); } int hashedID = HelperTools.GetDeterministicHashCode(_ID); if (udpSenders.TryGetValue(hashedID, out PlayPeerInfo p)) { p.IP = _dstIP; p.Port = _dstPort; p.NIC = _nic; return(true); } return(false); }
public bool RemovePeer(string _id) { if (CurrentState != State.Stoped) { return(false); } return(udpSenders.Remove(HelperTools.GetDeterministicHashCode(_id))); }
public void SetPeerEnabled(string _id, bool enabled) { int hashedID = HelperTools.GetDeterministicHashCode(_id); if (udpSenders.TryGetValue(hashedID, out PlayPeerInfo p)) { p.IsEnabled = enabled; } }
private void FillHeader(long _time, string _ID, int _size, byte[] _buffer, ushort[] ipChunks, int _port) { // Time 8 HelperTools.Long2Bytes(_buffer, 0, _time); // Hashed ID 4 HelperTools.Int32Bytes(_buffer, 8, HelperTools.GetDeterministicHashCode(_ID)); // IP 4 for (int i = 0; i < 4; i++) { _buffer[12 + i] = (byte)ipChunks[i]; } // Port 4 HelperTools.Int32Bytes(_buffer, 16, _port); // Size 4 HelperTools.Int32Bytes(_buffer, 20, _size); }
public ICollection <PlayPeerInfo> LoadFile(string _filePath, out DateTime _startTime, out int _lastTime) { Stop(); _lastTime = 0; filePath = _filePath; idxFilePath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath)) + ".idx"; // Init times lastTime = 0; _startTime = DateTime.MinValue; timeIndexes.Clear(); int nPeers = 0; udpSendersOriginal.Clear(); udpSenders.Clear(); _dataRate.Clear(); using (FileStream idxFile = new FileStream(idxFilePath, FileMode.Open, FileAccess.Read)) using (BinaryReader idxBinaryReader = new BinaryReader(idxFile)) { int time = 0; long position = 0; byte[] auxBuff = bytePool.Rent(4096); // Read DateTime, Secs Interval and Peers info if (idxBinaryReader.Read(auxBuff, 0, 16) == 16) { RecDateTime = _startTime = HelperTools.fromMillis(BitConverter.ToInt64(auxBuff, 0)); secsIdxInterval = BitConverter.ToInt32(auxBuff, 8); nPeers = BitConverter.ToInt32(auxBuff, 12); // Read peers for (int i = 0; i < nPeers; i++) { string ID = HelperTools.Bytes2StringWithLength(idxFile); string IP = HelperTools.Bytes2StringWithLength(idxFile); int Port = idxBinaryReader.ReadInt32(); udpSenders.Add(HelperTools.GetDeterministicHashCode(ID), new PlayPeerInfo { ID = ID, IP = IP, Port = Port }); udpSendersOriginal.Add(HelperTools.GetDeterministicHashCode(ID), new PlayPeerInfo { ID = ID, IP = IP, Port = Port }); _dataRate[ID] = 0f; } // Get All times to cache while (idxBinaryReader.Read(auxBuff, 0, HelperTools.idxIndexSize) == HelperTools.idxIndexSize) { time = BitConverter.ToInt32(auxBuff, 0); position = BitConverter.ToInt64(auxBuff, 4); try { timeIndexes.Add(time, position); } catch (Exception e) { logger?.LogError(e, "Error reading idx file. TimeIndexes"); } } _lastTime = lastTime = time; } bytePool.Return(auxBuff); } return(udpSenders.Values); }