Skip to content

Network simulator settings are ignored #213

@dbechrd

Description

@dbechrd

I've noticed a number of places in the tests, such as this:

yojimbo/test.cpp

Lines 1454 to 1464 in c868d55

void CreateClients( int numClients, Client ** clients, const Address & address, const ClientServerConfig & config, Adapter & _adapter, double time )
{
for ( int i = 0; i < numClients; ++i )
{
clients[i] = YOJIMBO_NEW( GetDefaultAllocator(), Client, GetDefaultAllocator(), address, config, _adapter, time );
clients[i]->SetLatency( 250 );
clients[i]->SetJitter( 100 );
clients[i]->SetPacketLoss( 25 );
clients[i]->SetDuplicates( 25 );
}
}

Where we're calling client->SetLatency() etc. on a newly allocated client. If you look at the implementation for this setter, it doesn't do anything when networkSimulator is null:

void BaseClient::SetLatency( float milliseconds )
{
if ( m_networkSimulator )
{
m_networkSimulator->SetLatency( milliseconds );
}
}

I also noticed this happening in the soak test:

yojimbo/soak.cpp

Lines 75 to 82 in c868d55

Client client( GetDefaultAllocator(), Address("0.0.0.0"), config, adapter, time );
client.SetLatency( 1000.0f );
client.SetJitter( 100.0f );
client.SetPacketLoss( 25.0f );
client.SetDuplicates( 25.0f );
client.InsecureConnect( privateKey, clientId, serverAddress );

These set calls should all be moved to after the InsecureConnect() call, because that's when the networkSimulator gets created (indirectly, via CreateInternal():

if ( m_config.networkSimulator )
{
m_networkSimulator = YOJIMBO_NEW( *m_clientAllocator, NetworkSimulator, *m_clientAllocator, m_config.maxSimulatorPackets, m_time );
}

This maybe happens with some server instances, too; I don't remember. I'm not going to submit a PR for this as I don't remember all the places it happens, and don't have the energy to audit it right now, but I wanted to document the problem in an issue.

This should be audited properly at some point by searching for all calls to those setters and ensuring they're happening on a valid networkSimulator instance. Alternatively, maybe the setters should just assert() when networkSimulator is null instead of silently ignore the parameters, so that it's not possible to call the setters when the networkSimulator doesn't exist, because who would ever want that anyways? The assert would make it very easy for users to notice when they messed up, vs. the network simulator not having the latency/jitter you expect, which is very difficult to notice since the tests still pass. 🤷

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions