public DHTClient(IPEndPoint localEndPoint, IDHTPeersHolder peersHolder, string clientVer) : base(localEndPoint) { fPeersHolder = peersHolder; fLocalID = peersHolder.ClientNodeId; fClientVer = clientVer; fLogger = LogManager.GetLogger(ProtocolHelper.LOG_FILE, ProtocolHelper.LOG_LEVEL, "DHTClient"); fRoutingTable = new DHTRoutingTable(KTableSize); fTransactions = new DHTTransactions(); }
public DHTClient(IPAddress addr, int port, IDHTPeersHolder peersHolder, string clientVer) { fBuffer = new byte[65535]; fClientVer = clientVer; fDefaultIP = new IPEndPoint(IPLoopbackAddress, 0); fLocalID = DHTHelper.GetRandomID(); fLocalIP = new IPEndPoint(addr, port); fLogger = LogManager.GetLogger(ProtocolHelper.LOG_FILE, ProtocolHelper.LOG_LEVEL, "DHTClient"); fPeersHolder = peersHolder; fRoutingTable = new DHTRoutingTable(KTableSize); fSearchRunned = false; fTransactions = new Dictionary <int, DHTMessage>(); fSocket = new Socket(IPAddressFamily, SocketType.Dgram, ProtocolType.Udp); // FIXME: unsupported? #if !__MonoCS__ fSocket.SetIPProtectionLevel(IPProtectionLevel.Unrestricted); #if !IP6 const long IOC_IN = 0x80000000; const long IOC_VENDOR = 0x18000000; const long SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12; byte[] optionInValue = { Convert.ToByte(false) }; byte[] optionOutValue = new byte[4]; fSocket.IOControl((IOControlCode)SIO_UDP_CONNRESET, optionInValue, optionOutValue); #else #endif #endif #if !IP6 fSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); fSocket.Ttl = 255; #else fSocket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false); #endif fSocket.Bind(fLocalIP); }