Double check if connection_type and sessionContext agree

Assuming that sessionContext is not null because connection_type is
CONNECTED is not safe. Fixed this in the peer_connect method
This commit is contained in:
John Jones 2017-10-09 10:00:30 -05:00
parent 6c8535198f
commit 68242a6355

View file

@ -97,6 +97,9 @@ int libp2p_peer_handle_connection_error(struct Libp2pPeer* peer) {
* @returns true(1) on success, false(0) if we could not connect * @returns true(1) on success, false(0) if we could not connect
*/ */
int libp2p_peer_connect(const struct RsaPrivateKey* privateKey, struct Libp2pPeer* peer, struct Peerstore* peerstore, struct Datastore *datastore, int timeout) { int libp2p_peer_connect(const struct RsaPrivateKey* privateKey, struct Libp2pPeer* peer, struct Peerstore* peerstore, struct Datastore *datastore, int timeout) {
// fix the connection type if in an invalid state
if (peer->connection_type == CONNECTION_TYPE_CONNECTED && peer->sessionContext == NULL)
peer->connection_type = CONNECTION_TYPE_NOT_CONNECTED;
libp2p_logger_debug("peer", "Attemping to connect to %s.\n", libp2p_peer_id_to_string(peer)); libp2p_logger_debug("peer", "Attemping to connect to %s.\n", libp2p_peer_id_to_string(peer));
time_t now, prev = time(NULL); time_t now, prev = time(NULL);
// find an appropriate address // find an appropriate address