paulo@0: /* paulo@0: * $Id: gt_node.h,v 1.36 2005/01/04 15:00:51 mkern Exp $ paulo@0: * paulo@0: * Copyright (C) 2001-2003 giFT project (gift.sourceforge.net) paulo@0: * paulo@0: * This program is free software; you can redistribute it and/or modify it paulo@0: * under the terms of the GNU General Public License as published by the paulo@0: * Free Software Foundation; either version 2, or (at your option) any paulo@0: * later version. paulo@0: * paulo@0: * This program is distributed in the hope that it will be useful, but paulo@0: * WITHOUT ANY WARRANTY; without even the implied warranty of paulo@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU paulo@0: * General Public License for more details. paulo@0: */ paulo@0: paulo@0: #ifndef GIFT_GT_NODE_H_ paulo@0: #define GIFT_GT_NODE_H_ paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: #define MAX_NODES gt_config_get_int("main/max_nodes=2000") paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: struct gt_query_router; paulo@0: struct gt_packet; paulo@0: struct gt_vendor_msg; paulo@0: struct gt_rx_stack; paulo@0: struct gt_tx_stack; paulo@0: paulo@0: typedef enum gt_node_state paulo@0: { paulo@0: GT_NODE_DISCONNECTED = 0x00, /* functionless node */ paulo@0: GT_NODE_CONNECTING_1 = 0x01, /* pending */ paulo@0: GT_NODE_CONNECTING_2 = 0x02, /* waiting for first ping response */ paulo@0: GT_NODE_CONNECTED = 0x08, /* first packet is seen */ paulo@0: GT_NODE_ANY = 0xFF, /* any state */ paulo@0: } gt_node_state_t; paulo@0: paulo@0: typedef enum gt_node_class paulo@0: { paulo@0: GT_NODE_NONE = 0x00, paulo@0: GT_NODE_LEAF = 0x01, /* plain 0.6 or 0.4 nodes */ paulo@0: GT_NODE_ULTRA = 0x02, /* ultrapeers */ paulo@0: GT_NODE_DEAD = 0x04, /* node is marked for deletion (unused) */ paulo@0: } gt_node_class_t; paulo@0: paulo@0: typedef struct gt_node paulo@0: { paulo@0: in_addr_t ip; paulo@0: paulo@0: /* the gnutella port of the other side */ paulo@0: in_port_t gt_port; paulo@0: paulo@0: /* the port the other side came from, could be the same as gt_port */ paulo@0: in_port_t peer_port; paulo@0: paulo@0: /* IP address used in communication with this node */ paulo@0: in_addr_t my_ip; paulo@0: paulo@0: /* HTTP headers the other node sent on 0.6 connection in stage-2 of paulo@0: * the 3-way handshake */ paulo@0: Dataset *hdr; paulo@0: paulo@0: /* Contains all the vendor messages supported by this node */ paulo@0: Dataset *vmsgs_supported; paulo@0: paulo@0: unsigned int incoming : 1; /* incoming connection */ paulo@0: unsigned int verified : 1; /* port has been verified */ paulo@0: unsigned int firewalled : 1; /* firewalled connection */ paulo@0: unsigned int tried_connect : 1; /* used internally by gt_netorg.c */ paulo@0: unsigned int rx_inflated : 1; /* incoming traffic compressed */ paulo@0: unsigned int tx_deflated : 1; /* outgoing traffic compressed */ paulo@0: unsigned int vmsgs_sent : 1; /* sent our initial batch of vmsgs */ paulo@0: paulo@0: /* current state of the given connection */ paulo@0: gt_node_state_t state; paulo@0: paulo@0: /* node classification that this connection is communicating with */ paulo@0: gt_node_class_t klass; paulo@0: paulo@0: /* TCPC a node uses. could be null */ paulo@0: TCPC *c; paulo@0: paulo@0: /* consecutive number of pings the host has not replied to */ paulo@0: unsigned int pings_with_noreply; paulo@0: paulo@0: /* push proxy address, which may be different from peer address if remote paulo@0: * end is multi-homed */ paulo@0: in_addr_t push_proxy_ip; paulo@0: in_port_t push_proxy_port; paulo@0: paulo@0: /* Data source for packets being read in */ paulo@0: struct gt_rx_stack *rx_stack; paulo@0: /* Data source for packets being sent out */ paulo@0: struct gt_tx_stack *tx_stack; paulo@0: paulo@0: /* TCPC used for port verification */ paulo@0: TCPC *gt_port_verify; paulo@0: paulo@0: /* identifier for this node in the GUID cache */ paulo@0: unsigned long id; paulo@0: paulo@0: /* stats information */ paulo@0: unsigned long size_kb; paulo@0: unsigned long files; paulo@0: paulo@0: /* timers for node things */ paulo@0: timer_id handshake_timer; paulo@0: timer_id search_timer; paulo@0: timer_id query_route_timer; paulo@0: paulo@0: /* around the time of the last connect to this node */ paulo@0: time_t vitality; paulo@0: paulo@0: /* number of disconnections from this node */ paulo@0: unsigned int disconnect_cnt; paulo@0: paulo@0: /* guid of the last ping from this node */ paulo@0: gt_guid_t *ping_guid; paulo@0: paulo@0: /* time of the last ping from this node */ paulo@0: time_t last_ping_time; paulo@0: paulo@0: /* start of the last connect to this node */ paulo@0: time_t start_connect_time; paulo@0: paulo@0: /* time the last connection made to this node lasted */ paulo@0: time_t last_connect_duration; paulo@0: paulo@0: /* total amount of time we have been connected to this node */ paulo@0: time_t total_connect_duration; paulo@0: paulo@0: /* status of shares submitted to this node */ paulo@0: struct gt_share_state *share_state; paulo@0: paulo@0: /* router for query packets */ paulo@0: struct gt_query_router *query_router; paulo@0: paulo@0: /* version of the query router table submitted to this node currently */ paulo@0: int query_router_counter; paulo@0: } GtNode; paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: #define GT_NODE(c) ((GtNode *)c->udata) paulo@0: #define GT_CONN(node) ((TCPC *) node->c) paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: GtNode *gt_node_new (void); paulo@0: GtNode *gt_node_instantiate (TCPC *c); paulo@0: void gt_node_free (GtNode *node); paulo@0: BOOL gt_node_freeable (GtNode *node); paulo@0: paulo@0: char *gt_node_str (GtNode *node); paulo@0: void gt_node_connect (GtNode *node, TCPC *c); paulo@0: void gt_node_disconnect (TCPC *c); paulo@0: void gt_node_error (TCPC *c, const char *fmt, ...); paulo@0: paulo@0: void gt_node_remove_all (void); paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: void gt_node_state_set (GtNode *node, gt_node_state_t state); paulo@0: void gt_node_class_set (GtNode *node, gt_node_class_t klass); paulo@0: paulo@0: char *gt_node_class_str (gt_node_class_t klass); paulo@0: char *gt_node_state_str (gt_node_state_t state); paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: GtNode *gt_node_lookup (in_addr_t ip, in_port_t port); paulo@0: GtNode *gt_node_register (in_addr_t ip, in_port_t port, paulo@0: gt_node_class_t klass); paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: BOOL gt_node_send_if_supported (GtNode *node, struct gt_packet *pkt); paulo@0: BOOL gt_node_send (GtNode *node, struct gt_packet *pkt); paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: #endif /* GIFT_GT_NODE_H_ */