static void read_peer_id (CcnetHandshake *handshake, ccnet_packet *packet) { uint16_t len; char *id; /* get id */ len = packet->header.length; id = g_malloc (len + 1); memcpy (id, packet->data, len); id[len] = '\0'; handshake->id = id; if (handshake->state == INIT) { /* we are the slave */ ccnet_debug ("[Conn] Incoming: Read peer id %.8s\n", id); send_handshake_message (handshake); handshake->state = ID_RECEIVED; } else if (handshake->state == ID_SENT) { /* we are the master */ ccnet_debug ("[Conn] Outgoing: Read peer %s id %.8s\n", handshake->peer->name, id); if (g_strcmp0 (handshake->peer->id, handshake->id) != 0) { ccnet_warning ("[Conn] Received peer id does not match.\n"); ccnet_handshake_done (handshake, FALSE); return; } send_ack (handshake); ccnet_handshake_done (handshake, TRUE); } }
static void read_ok (CcnetHandshake *handshake, ccnet_packet *packet) { if (packet->header.type != CCNET_MSG_OK) { ccnet_warning ("[Conn] Read wrong ack format\n"); ccnet_handshake_done (handshake, FALSE); } else { ccnet_debug ("[Conn] Incoming: Read ack (%.10s)\n", handshake->id); ccnet_handshake_done (handshake, TRUE); } return; }
void ccnet_handshake_abort (CcnetHandshake * handshake) { ccnet_handshake_done (handshake, FALSE); }