version 1.4 | | version 1.5 |
---|
| | |
ip_sendtoca(*addr.goodaddr,buf,s); | | ip_sendtoca(*addr.goodaddr,buf,s); |
hsb->nextsend=timer_get_approx_seconds()+IP_HS_RETRYTIME; | | hsb->nextsend=timer_get_approx_seconds()+IP_HS_RETRYTIME; |
hsb->attempts++; | | hsb->attempts++; |
/*#ifdef UDPDEBUG | | #ifdef UDPDEBUG_HS |
{ | | { |
int hj; | | printf(MSGHDR"sending handshake %i (t%i state %i(%s)) for (%p)",hsb->attempts,hsb->type,hsb->state,ip_hs_statetoa(hsb->state),addr.goodaddr); |
printf(MSGHDR"sending handshake %i (t%i state %i(%s)) for (%i)",hsb->attempts,hsb->type,hsb->state,ip_hs_statetoa(hsb->state),addr.goodaddr); | | ip_addr_list::iterator i; |
for (hj=0;hj<numaddr;hj++){ | | for (i=addr.begin();i!=addr.end();i++) { |
if (hj>0) | | if (i!=addr.begin()) |
printf(", "); | | printf(", "); |
dumpraddr(addr[hj].addr); | | i->dump(); |
} | | } |
printf(" v%i\n",iver); | | printf(" v%i\n",iver); |
} | | } |
#endif*/ | | #endif |
} | | } |
bool ip_peer::verify_addr(ip_addr_list &fraddrs){ | | bool ip_peer::verify_addr(ip_addr_list &fraddrs){ |
int a1=addr.add(fraddrs); | | int a1=addr.add(fraddrs); |
| | |
//if (hsb->state<IPNOSTATE && hsb->nextsend<mintime){ | | //if (hsb->state<IPNOSTATE && hsb->nextsend<mintime){ |
if ((hsb->state & STATE_NEED_RESEND) && hsb->nextsend<mintime){ | | if ((hsb->state & STATE_NEED_RESEND) && hsb->nextsend<mintime){ |
if(hsb->attempts>IP_MAX_HS_ATTEMPTS){ | | if(hsb->attempts>IP_MAX_HS_ATTEMPTS){ |
/*#ifdef UDPDEBUG | | #ifdef UDPDEBUG_HS |
int hj; | | printf(MSGHDR"handshake timeout (state %i(%s)) for (%p)",hsb->state,ip_hs_statetoa(hsb->state),peer->addr.goodaddr); |
printf(MSGHDR"handshake timeout (state %i(%s)) for (%i)",hsb->state,ip_hs_statetoa(hsb->state),peer->goodaddr); | | ip_addr_list::iterator i; |
for (hj=0;hj<peer->numaddr;hj++){ | | for (i=peer->addr.begin();i!=peer->addr.end();i++) { |
if (hj>0) | | if (i!=peer->addr.begin()) |
printf(", "); | | printf(", "); |
dumpraddr(peer->addr[hj].addr); | | i->dump(); |
} | | } |
printf(" v%i\n",peer->iver); | | printf(" v%i\n",peer->iver); |
#endif*/ | | #endif |
hsb->setstate(STATE_ERR); | | hsb->setstate(STATE_ERR); |
}else{ | | }else{ |
// handshake_buf.state=handshakers[i].state; | | // handshake_buf.state=handshakers[i].state; |
| | |
switch(buf[0]){ | | switch(buf[0]){ |
case IP_CFG_SORRY: | | case IP_CFG_SORRY: |
{ | | { |
#ifdef UDPDEBUG | | #ifdef UDPDEBUG_HS |
printf("ip_receive_cfg: %i %i ",buf[0],buf[1]); | | printf("ip_receive_cfg: %i %i ",buf[0],buf[1]); |
dumprid(buf+2); | | dumprid(buf+2); |
printf(" v%i tryid%u\n",ntohs(*(unsigned short*)(buf+8)),(unsigned int)ntohl(*(u_int32_t*)(buf+10))); | | printf(" v%i tryid%u\n",ntohs(*(unsigned short*)(buf+8)),(unsigned int)ntohl(*(u_int32_t*)(buf+10))); |
| | |
| | |
}break; | | }break; |
case IP_CFG_HANDSHAKE: | | case IP_CFG_HANDSHAKE: |
#ifdef UDPDEBUG | | #ifdef UDPDEBUG_HS |
printf("ip_receive_cfg: %i %i ",buf[0],buf[1]); | | printf("ip_receive_cfg: %i %i ",buf[0],buf[1]); |
dumprid(buf+2); | | dumprid(buf+2); |
printf(" v%i tryid%u\n",ntohs(*(unsigned short*)(buf+8)),(unsigned int)ntohl(*(u_int32_t*)(buf+10))); | | printf(" v%i tryid%u\n",ntohs(*(unsigned short*)(buf+8)),(unsigned int)ntohl(*(u_int32_t*)(buf+10))); |
| | |
hsi->addr.add(fromaddr); | | hsi->addr.add(fromaddr); |
ip_handshake_info *lhsi=NULL; | | ip_handshake_info *lhsi=NULL; |
p=peer_list.find_byid(hsi->id); | | p=peer_list.find_byid(hsi->id); |
/*#ifdef UDPDEBUG | | #ifdef UDPDEBUG_HS |
printf("hsi %i %i id=",hsi->type,hsi->state); | | printf("hsi %i %i id=",hsi->type,hsi->state); |
hsi->id.dump(); | | hsi->id.dump(); |
printf(" ver=%i tryid=%u\n",hsi->iver,hsi->tryid); | | printf(" ver=%i tryid=%u\n",hsi->iver,hsi->tryid); |
mprintf((0,"peer_list.find_byid=%p\n",p)); | | mprintf((0,"peer_list.find_byid=%p\n",p)); |
#endif*/ | | #endif |
if (!p){ | | if (!p){ |
p=peer_list.find_unk_by_addr(fromaddr); | | p=peer_list.find_unk_by_addr(fromaddr); |
// mprintf((0,"peer_list.find_by_addr=%p\n",p)); | | // mprintf((0,"peer_list.find_by_addr=%p\n",p)); |
| | |
{ | | { |
ip_peer *rp; | | ip_peer *rp; |
ip_handshake_relay hsr(buf); | | ip_handshake_relay hsr(buf); |
#ifdef UDPDEBUG | | #ifdef UDPDEBUG_HS |
printf("ip_receive_cfg: %i %i ",buf[0],buf[1]); | | printf("ip_receive_cfg: %i %i ",buf[0],buf[1]); |
dumprid(buf+2); | | dumprid(buf+2); |
printf(" v%i r_id ",ntohs(*(unsigned short*)(buf+8))); | | printf(" v%i r_id ",ntohs(*(unsigned short*)(buf+8))); |
| | |
if (!rhsr) | | if (!rhsr) |
break; | | break; |
rhsr->setstate(0); | | rhsr->setstate(0); |
#ifdef UDPDEBUG | | #ifdef UDPDEBUG_HS |
printf("**** "); | | printf("**** "); |
p->id.dump(); | | p->id.dump(); |
printf(" is ok with "); | | printf(" is ok with "); |