int track_packet_host(Packet *p) { struct ipaddr addr; addr = packet_srcaddr(p); HostData *host = host_get((HostKey *)&addr); if (host == NULL) { if ((host = calloc(1, sizeof *host)) == NULL) { warn("could not allocate host data"); return -1; } if (host_insert((HostKey *)&addr, host) < 0) return -1; memset(host, 0, sizeof *host); host->address = packet_srcaddr(p); host->version = packet_version(p); } if (host != NULL) { host->tx_packets++; host->tx_octets += packet_paysize(p); } addr = packet_dstaddr(p); host = host_get((HostKey *)&addr); if (host == NULL) { if ((host = calloc(1, sizeof *host)) == NULL) { warn("could not allocate host data"); return -1; } if (host_insert((HostKey *)&addr, host) < 0) return -1; memset(host, 0, sizeof *host); host->address = packet_dstaddr(p); host->version = packet_version(p); } if (host != NULL) { host->rx_packets++; host->rx_octets += packet_paysize(p); } tmq_timeout(timeout_queue); return 0; }
int net_send_version(struct peer *peer, int start_height) { struct packet *packet; int ret; packet = packet_version(peer, start_height); ret = packet_send(peer, packet); packet_free(packet); return ret; }