bool deser_msg_getblocks(struct msg_getblocks *gb, struct const_buffer *buf) { msg_getblocks_free(gb); if (!deser_bp_locator(&gb->locator, buf)) return false; if (!deser_u256(&gb->hash_stop, buf)) return false; return true; }
static bool nc_msg_verack(struct nc_conn *conn) { if (conn->seen_verack) return false; conn->seen_verack = true; if (debugging) fprintf(plog, "net: %s verack\n", conn->addr_str); /* * When a connection attempt is made, the peer is deleted * from the peer list. When we successfully connect, * the peer is re-added. Thus, peers are immediately * forgotten if they fail, on the first try. */ conn->peer.last_ok = time(NULL); conn->peer.n_ok++; conn->peer.addr.nTime = (uint32_t) conn->peer.last_ok; peerman_add(conn->nci->peers, &conn->peer, true); /* request peer addresses */ if ((conn->protover >= CADDR_TIME_VERSION) && (!nc_conn_send(conn, "getaddr", NULL, 0))) return false; LOG("req addr success, now request blocks"); /* request blocks */ bool rc = true; time_t now = time(NULL); time_t cutoff = now - (24 * 60 * 60); if (conn->nci->last_getblocks < cutoff) { LOG("compose blocks message"); struct msg_getblocks gb; msg_getblocks_init(&gb); blkdb_locator(&db, NULL, &gb.locator); cstring *s = ser_msg_getblocks(&gb); rc = nc_conn_send(conn, "getblocks", s->str, s->len); cstr_free(s, true); msg_getblocks_free(&gb); conn->nci->last_getblocks = now; } return rc; }