[ENet-discuss] Preventing a host from connecting multiple times to another host?

Lee Salzman lsalzman1 at cox.net
Thu Jun 17 03:59:35 PDT 2010


The risks of doing that are in fact the behavior you are trying to 
cause: denying multiple connections from the same host and port.

There are perfectly legitimate cases where this can happen, such as an 
old connection from the same host/port that is a zombie or on its way to 
being a zombie due to a timeout, and a new one coming in that is trying 
to replace it. In this case you would still likely need the connectID, 
but some more coarse way of updating connectID, i.e. all 4 of your 
connect requests would have the same connectID, but if the connection 
later drops and needs to be reinitiated, the connectID needs to differ.

Lee

Benoit Germain wrote:
> Hello,
>
> I am attempting a little LAN-matchmaking prototype using a wrapper over ENet. The idea is the following:
>
> One or more players (the 'servers') create a ENet host bound to a given port, and accepting a given number of connections.
>
> Other players (the 'clients') each create a host that initiate several broadcast connections toward that same port. What I want is for each 'server' to establish one valid connection for each separate 'client'. Unfortunately, this doesn't seem to be the case. Let's say that I have a single server accepting 4 connections, and a single client issuing 4 connection request, all 4 of them will be validated by the same server.
>
> If I understand well, there already is some rejection mechanism that looks like it is more suited to reject packet duplicates than multiple connection attempts from the same distant host:
>
> static ENetPeer *
> enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENetProtocol * command)
> {
> ...
>
>     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)
>           return NULL;
>     }
> ...
>
> So my question is twofold:
>
> Is it the expected behavior for a host to validate multiple connection attempts from a given distant host?
> What is the best way to change this behavior to ensure only one connection is ever active between two hosts? Removing the currentPeer -> connectID == command -> connect.connectID part of the test seems to do the trick, but what are the risks of doing this?
>
>
> Benoit.
>
>   



More information about the ENet-discuss mailing list