Hi,<br><br><br>I want to write a little app that needs to automatically discover existing peers inside a LAN.<br><br>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.<br>
<br>Now let's say I start with two hosts A and B with 10 peers each.<br><br>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:<br>
<br>in enet_protocol_handle_connect()<br>{<br> ...<br> for (currentPeer = host -> peers;<br> currentPeer < & host -> peers [host -> peerCount];<br> ++ currentPeer)<br> {<br> if (currentPeer -> state != ENET_PEER_STATE_DISCONNECTED &&<br>
currentPeer -> address.host == host -> receivedAddress.host &&<br> currentPeer -> address.port == host -> receivedAddress.port /*&&<br> currentPeer -> connectID == command -> connect.connectID*/) // THIS PART IS DISABLED TO PREVENT MULTIPLE CONNECTIONS BETWEEN THE SAME HOSTS<br>
return NULL;<br> }<br> ...<br>}<br><br>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?<br>
<br>And more generally, what is the interest of authorizing several peers of a given host to connect to another host?<br><br>Regards,<br><br clear="all"><br>-- <br>Benoit.<br>