[ENet-discuss] LAN chat-like app with automatic peer discovery

Benoit Germain bnt.germain at gmail.com
Mon Feb 18 06:51:21 PST 2013


Hi,


I want to write a little app that needs to automatically discover existing
peers inside a LAN.

Each instance launches one host that accepts a given number of peers. Then
it attempts to connect to the ENET_BROADCAST address. Since new hosts can
appear at random, a new connection attempt is made each second. Thus after
a while every peer should connect to every existing host in the LAN.

Now let's say I start with two hosts A and B with 10 peers each.

In vanilla ENet implementation, each connection attempt issued by host A
will bind itself to host B, resulting in all peers on a given host
connected to the other host. I have changed ENet code as follows so that
when several connection attempts are issues by host A, only one can ever
succeed with host B:

in enet_protocol_handle_connect()
{
   ...
    for (currentPeer = host -> peers;
         currentPeer < & host -> peers [host -> peerCount];
         ++ currentPeer)
    {
        if (currentPeer -> state != ENET_PEER_STATE_DISCONNECTED &&
            currentPeer -> address.host == host -> receivedAddress.host &&
            currentPeer -> address.port == host -> receivedAddress.port /*&&
            currentPeer -> connectID == command -> connect.connectID*/) //
THIS PART IS DISABLED TO PREVENT MULTIPLE CONNECTIONS BETWEEN THE SAME HOSTS
          return NULL;
    }
   ...
}

However, this is not enough: I observe that host A will only bind one peer
to host B successfully, but host B will also successfully bind one peer to
host A, thus resulting in hosts A and B having each 2 peers connected to
their counterpart. How can I prevent this?

And more generally, what is the interest of authorizing several peers of a
given host to connect to another host?

Regards,


-- 
Benoit.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20130218/d7b58a27/attachment.html>


More information about the ENet-discuss mailing list