void MockUDPSocket::AddExpectedData(IOQueue *ioqueue, const IPV4SocketAddress &dest) { unsigned int size; uint8_t *data = IOQueueToBuffer(ioqueue, &size); expected_call call = {data, size, dest.Host(), dest.Port(), true}; m_expected_calls.push(call); }
void AdvancedTCPConnector::Disconnect(const IPV4SocketAddress &endpoint, bool pause) { IPPortPair key(endpoint.Host(), endpoint.Port()); ConnectionMap::iterator iter = m_connections.find(key); if (iter == m_connections.end()) return; if (iter->second->state != CONNECTED) return; iter->second->failed_attempts = 0; if (pause) { iter->second->state = PAUSED; } else { // schedule a retry as if this endpoint failed once iter->second->state = DISCONNECTED; iter->second->retry_timeout = m_ss->RegisterSingleTimeout( iter->second->policy->BackOffTime(1), ola::NewSingleCallback( this, &AdvancedTCPConnector::RetryTimeout, iter->first)); } }
/** * Inject the data in an IOQueue into the socket. This acts as if the data was * received on the UDP socket. * @param ioqueue the data to inject * @param source the socket address where this fake data came from */ void MockUDPSocket::InjectData(IOQueue *ioqueue, const IPV4SocketAddress &source) { unsigned int data_size; // This incurs a copy, but this is just testing code so it doesn't matter. uint8_t *data = IOQueueToBuffer(ioqueue, &data_size); expected_call call = {data, data_size, source.Host(), source.Port(), true}; m_received_data.push(call); PerformRead(); }
void AdvancedTCPConnector::RemoveEndpoint(const IPV4SocketAddress &endpoint) { IPPortPair key(endpoint.Host(), endpoint.Port()); ConnectionMap::iterator iter = m_connections.find(key); if (iter == m_connections.end()) return; AbortConnection(iter->second); delete iter->second; m_connections.erase(iter); }
void AdvancedTCPConnector::Resume(const IPV4SocketAddress &endpoint) { IPPortPair key(endpoint.Host(), endpoint.Port()); ConnectionMap::iterator iter = m_connections.find(key); if (iter == m_connections.end()) return; if (iter->second->state == PAUSED) { iter->second->state = DISCONNECTED; AttemptConnection(iter->first, iter->second); } }
bool AdvancedTCPConnector::GetEndpointState( const IPV4SocketAddress &endpoint, ConnectionState *connected, unsigned int *failed_attempts) const { IPPortPair key(endpoint.Host(), endpoint.Port()); ConnectionMap::const_iterator iter = m_connections.find(key); if (iter == m_connections.end()) return false; *connected = iter->second->state; *failed_attempts = iter->second->failed_attempts; return true; }
bool CheckIfMaster() { vector<Master>::iterator iter = m_masters.begin(); uint8_t priority = 0; Master *preferred_master = NULL; for (; iter != m_masters.end(); ++iter) { if (iter->priority > priority && iter->address.Host() != IPV4Address::WildCard()) { preferred_master = &(*iter); priority = iter->priority; } } return (preferred_master && preferred_master->address.Port() == m_listen_address.Port() && STLContains(m_local_ips, preferred_master->address.Host())); }
/** * Add a remote host. This will trigger the connection process to start. * If the ip:port already exists this won't do anything. * When the connection is successfull the on_connect callback will be run, and * ownership of the TCPSocket object is transferred. * @param endpoint the IPV4SocketAddress to connect to. * @param backoff_policy the BackOffPolicy to use for this connection. * @param paused true if we don't want to immediately connect to this peer. */ void AdvancedTCPConnector::AddEndpoint(const IPV4SocketAddress &endpoint, BackOffPolicy *backoff_policy, bool paused) { IPPortPair key(endpoint.Host(), endpoint.Port()); ConnectionMap::iterator iter = m_connections.find(key); if (iter != m_connections.end()) return; // new ip:port ConnectionInfo *state = new ConnectionInfo; state->state = paused ? PAUSED : DISCONNECTED; state->failed_attempts = 0; state->retry_timeout = ola::thread::INVALID_TIMEOUT; state->connection_id = 0; state->policy = backoff_policy; m_connections[key] = state; if (!paused) AttemptConnection(key, state); }
/** * Ownership of the data is not transferred. */ void MockUDPSocket::InjectData(const uint8_t *data, unsigned int size, const IPV4SocketAddress &source) { InjectData(data, size, source.Host(), source.Port()); }