/** *struct msg_addr { parr *addrs; //bp_address array }; */ static bool nc_msg_addr(struct nc_conn *conn) { struct const_buffer buf = { conn->msg.data, conn->msg.hdr.data_len }; struct msg_addr ma; bool rc = false; msg_addr_init(&ma);/* just a memset 0*/ if (!deser_msg_addr(conn->protover, &ma, &buf)) goto out; unsigned int i; time_t cutoff = time(NULL) - (7 * 24 * 60 * 60); if (debugging) { unsigned int old = 0; for (i = 0; i < ma.addrs->len; i++) { struct bp_address *addr = parr_idx(ma.addrs, i); if (addr->nTime < cutoff) old++; } fprintf(plog, "net: %s addr(%zu addresses, %u old)\n", conn->addr_str, ma.addrs->len, old); } /* ignore ancient addresses */ if (conn->protover < CADDR_TIME_VERSION){ LOG("all addresses rejected because protover < CADDR_TIME_VERSION"); goto out_ok; } /* feed addresses to peer manager */ int l_cnt = 0; for (i = 0; i < ma.addrs->len; i++) { struct bp_address *addr = parr_idx(ma.addrs, i); if (addr->nTime > cutoff){ l_cnt++; peerman_add_addr(conn->nci->peers, addr, false); } } LOG("number of addresses added from peer:%d", l_cnt); out_ok: rc = true; out: msg_addr_free(&ma); return rc; }
static bool nc_msg_addr(struct nc_conn *conn) { struct const_buffer buf = { conn->msg.data, conn->msg.hdr.data_len }; struct msg_addr ma; bool rc = false; msg_addr_init(&ma); if (!deser_msg_addr(conn->protover, &ma, &buf)) goto out; unsigned int i; time_t cutoff = time(NULL) - (7 * 24 * 60 * 60); if (log_state->debug) { unsigned int old = 0; for (i = 0; i < ma.addrs->len; i++) { struct bp_address *addr = parr_idx(ma.addrs, i); if (addr->nTime < cutoff) old++; } log_debug("net: %s addr(%zu addresses, %u old)", conn->addr_str, ma.addrs->len, old); } /* ignore ancient addresses */ if (conn->protover < CADDR_TIME_VERSION) goto out_ok; /* feed addresses to peer manager */ for (i = 0; i < ma.addrs->len; i++) { struct bp_address *addr = parr_idx(ma.addrs, i); if (addr->nTime > cutoff) peerman_add_addr(conn->nci->peers, addr, false); } out_ok: rc = true; out: msg_addr_free(&ma); return rc; }