public bool IncomingBuddy(Kademlia.KadContact contact, Mpd.Generic.UInt128 buddyID) { uint nContactIP = (uint)IPAddress.NetworkToHostOrder(contact.IPAddress); //If eMule already knows this client, abort this.. It could cause conflicts. //Although the odds of this happening is very small, it could still happen. if (FindClientByIP(nContactIP, contact.TCPPort) != null) { return(false); } else if (IsKadFirewallCheckIP(nContactIP)) { // doing a kad firewall check with this IP, abort return(false); } else if (MuleApplication.Instance.ServerConnect.LocalIP == nContactIP && MuleApplication.Instance.Preference.Port == contact.TCPPort) { return(false); // don't connect ourself } //Add client to the lists to be processed. UpDownClient pNewClient = MuleApplication.Instance.CoreObjectManager.CreateUpDownClient(0, contact.TCPPort, contact.IPAddress, 0, 0, false); pNewClient.KadPort = contact.UDPPort; pNewClient.KadState = KadStateEnum.KS_INCOMING_BUDDY; pNewClient.UserHash = contact.ClientID.Bytes; pNewClient.BuddyID = buddyID.Bytes; AddToKadList(pNewClient); AddClient(pNewClient); return(true); }
public void RequestBuddy(Kademlia.KadContact contact, byte byConnectOptions) { uint nContactIP = (uint)IPAddress.NetworkToHostOrder(contact.IPAddress); // don't connect ourself if (MuleApplication.Instance.ServerConnect.LocalIP == nContactIP && MuleApplication.Instance.Preference.Port == contact.TCPPort) { return; } UpDownClient pNewClient = FindClientByIP(nContactIP, contact.TCPPort); if (pNewClient == null) { pNewClient = MuleApplication.Instance.CoreObjectManager.CreateUpDownClient(0, contact.TCPPort, contact.IPAddress, 0, 0, false); } else if (pNewClient.KadState != KadStateEnum.KS_NONE) { return; // already busy with this client in some way (probably fw stuff), don't mess with it } else if (IsKadFirewallCheckIP(nContactIP)) { // doing a kad firewall check with this IP, abort return; } //Add client to the lists to be processed. pNewClient.KadPort = contact.UDPPort; pNewClient.KadState = KadStateEnum.KS_QUEUED_BUDDY; pNewClient.UserHash = contact.ClientID.Bytes; pNewClient.SetConnectOptions(byConnectOptions, true, false); AddToKadList(pNewClient); //This method checks if this is a dup already. AddClient(pNewClient); }
public bool DoRequestFirewallCheckUDP(Kademlia.KadContact contact) { // first make sure we don't know this IP already from somewhere if (FindClientByIP((uint)IPAddress.NetworkToHostOrder(contact.IPAddress)) != null) { return(false); } // fine, justcreate the client object, set the state and wait // TODO: We don't know the clients usershash, this means we cannot build an obfuscated connection, which // again mean that the whole check won't work on "Require Obfuscation" setting, which is not a huge problem, // but certainly not nice. Only somewhat acceptable way to solve this is to use the KadID instead. UpDownClient pNewClient = MuleApplication.Instance.CoreObjectManager.CreateUpDownClient(0, contact.TCPPort, contact.IPAddress, 0, 0, false); pNewClient.KadState = KadStateEnum.KS_QUEUED_FWCHECK_UDP; AddToKadList(pNewClient); AddClient(pNewClient); return(true); }