Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

if/core/nodes.h

Go to the documentation of this file.
00001 /*
00002  * $Id: nodes.h 13870 2007-06-18 03:27:25Z cbiere $
00003  *
00004  * Copyright (c) 2001-2003, Raphael Manfredi, Richard Eckart
00005  *
00006  *----------------------------------------------------------------------
00007  * This file is part of gtk-gnutella.
00008  *
00009  *  gtk-gnutella is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  gtk-gnutella is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with gtk-gnutella; if not, write to the Free Software
00021  *  Foundation, Inc.:
00022  *      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *----------------------------------------------------------------------
00024  */
00025 
00026 #ifndef _if_core_nodes_h_
00027 #define _if_core_nodes_h_
00028 
00029 #include "common.h"
00030 
00031 #include "if/core/hosts.h"
00032 
00033 #include "lib/host_addr.h"
00034 #include "lib/vendors.h"
00035 
00036 struct node_id;
00037 typedef const struct node_id *node_id_t;
00038 
00039 node_id_t node_id_ref(const node_id_t node_id);
00040 void node_id_unref(const node_id_t node_id);
00041 
00042 const gchar *node_id_to_string(const node_id_t node_id);
00043 
00044 #define node_id_eq_func ((GCompareFunc) node_id_eq)
00045 gboolean node_id_eq(const node_id_t a, const node_id_t b);
00046 guint node_id_hash(gconstpointer node_id);
00047 
00051 enum rnode_mode {
00052     RNODE_M_AUTO = 0,
00053     RNODE_M_LEAF = 1,
00054     RNODE_M_ULTRA = 2,
00055 };
00056 
00060 typedef struct rnode_info {
00061     /* General information always returned */
00062     gchar vendor[4];            
00063     enum rnode_mode mode;       
00064     guint32 answer_flags;       
00065     guint32 op_flags;           
00066     guint32 features[2];        
00067     guint8 features_count;      
00068     guint8 max_ultra_up;        
00069     guint8 max_ultra_lf;        
00070     guint8 ultra_count;         
00071     guint8 ttl;                 
00072     guint8 hard_ttl;            
00073     guint16 max_leaves;         
00074     guint16 leaf_count;         
00075     guint32 startup_time;       
00076     guint32 ip_change_time;     
00077     /* Bandwidth information, optional */
00078     guint16 bw_flags;           
00079     guint32 gnet_bw_in;         
00080     guint32 gnet_bw_out;        
00081     guint32 gnet_bwl_in;        
00082     guint32 gnet_bwl_out;       
00083     /* Packets remote node dropped on this TCP connection */
00084     guint32 tx_dropped;         
00085     guint32 rx_dropped;         
00086     /* Query hit statistics */
00087     guint16 results_max;        
00088     guint32 file_hits;          
00089     guint32 qhits_tcp;          
00090     guint32 qhits_udp;          
00091     guint64 qhits_tcp_bytes;    
00092     guint64 qhits_udp_bytes;    
00093     /* CPU statistics */
00094     guint64 cpu_usr;            
00095     guint64 cpu_sys;            
00096     /* Information sent via optional GGEP blocks */
00097     guint32 ggep_du;            
00098     const gchar *ggep_ua;       
00099     host_addr_t ggep_ipv6;      
00100 } rnode_info_t;
00101 
00106 #define RNODE_RQ_GGEP_DU    0x00000001  
00107 #define RNODE_RQ_GGEP_LOC   0x00000002  
00108 #define RNODE_RQ_GGEP_IPV6  0x00000004  
00109 #define RNODE_RQ_GGEP_UA    0x00000008  
00110 #define RNODE_RQ_BW_INFO    0x00000010  
00111 #define RNODE_RQ_DROP_INFO  0x00000020  
00112 #define RNODE_RQ_QHIT_INFO  0x00000040  
00113 #define RNODE_RQ_CPU_INFO   0x00000080  
00114 #define RNODE_RQ_GGEP_GGEP  0x00000100  
00115 #define RNODE_RQ_GGEP_VMSG  0x00000200  
00120 #define RNODE_OF_TCP_FW     0x00000001  
00121 #define RNODE_OF_UDP_FW     0x00000002  
00122 #define RNODE_OF_DHT_ACTIVE 0x00000004  
00123 #define RNODE_OF_ANCIENT    0x00000008  
00124 #define RNODE_OF_NTP        0x00000010  
00125 #define RNODE_OF_HEADLESS   0x00000020  
00126 #define RNODE_OF_DHT_PASIVE 0x00000040  
00127 #define RNODE_OF_UDP        0x00000080  
00128 #define RNODE_OF_DNS_NAME   0x00000100  
00129 #define RNODE_OF_OOB        0x00000200  
00130 #define RNODE_OF_OOB_PROXY  0x00000400  
00131 #define RNODE_OF_OOB_REPLY  0x00000800  
00132 #define RNODE_OF_UDP_HOLE   0x00001000  
00133 #define RNODE_OF_OFFICIAL   0x00002000  
00138 #define RNODE_BW_STRICT     0x0001      
00139 #define RNODE_BW_IP4_TOS    0x0002      
00140 #define RNODE_BW_UP2UP_BW   0x0004      
00141 #define RNODE_BW_UP2LF_BW   0x0008      
00142 #define RNODE_BW_OUT_BW     0x0010      
00148 #define RNODE_O1_BROWSE     (1 << 0)    
00149 #define RNODE_O1_PFSP       (1 << 1)    
00150 #define RNODE_O1_CHAT       (1 << 2)    
00151 #define RNODE_O1_FW2FW      (1 << 3)    
00152 #define RNODE_O1_PPROXY     (1 << 4)    
00153 #define RNODE_O1_WHATSNEW   (1 << 5)    
00154 #define RNODE_O1_THEX       (1 << 6)    
00155 #define RNODE_O1_MAGNET     (1 << 7)    
00156 #define RNODE_O1_UHC        (1 << 8)    
00157 #define RNODE_O1_TCP_DEFL   (1 << 9)    
00158 #define RNODE_O1_UDP_DEFL   (1 << 10)   
00159 #define RNODE_O1_DYN_QUERY  (1 << 11)   
00160 #define RNODE_O1_ACTV_QUEUE (1 << 12)   
00161 #define RNODE_O1_PASV_QUEUE (1 << 13)   
00162 #define RNODE_O1_GWC_BOOT   (1 << 14)   
00163 #define RNODE_O1_UHC_BOOT   (1 << 15)   
00164 #define RNODE_O1_QHIT_XML   (1 << 16)   
00165 #define RNODE_O1_TCP_CRAWL  (1 << 17)   
00166 #define RNODE_O1_UDP_CRAWL  (1 << 18)   
00167 #define RNODE_O1_UP_QRP     (1 << 19)   
00168 #define RNODE_O1_LARGE_QRT  (1 << 20)   
00169 #define RNODE_O1_CHUNKED    (1 << 21)   
00170 #define RNODE_O1_RETRY_AFTER (1 << 22)  
00171 #define RNODE_O1_QUERY_SPEED (1 << 23)  
00172 #define RNODE_O1_TLS        (1 << 24)   
00173 #define RNODE_O1_OOB_HITS   (1 << 25)   
00174 #define RNODE_O1_OOB_PROXY  (1 << 26)   
00175 #define RNODE_O1_BYE        (1 << 27)   
00176 #define RNODE_O1_SWARMING   (1 << 28)   
00177 #define RNODE_O1_GGEP       (1 << 29)   
00178 #define RNODE_O1_DL_CE      (1 << 30)   
00179 #define RNODE_O1_UL_CE      (1 << 31)   
00185 #define RNODE_O2_GUESS      (1 << 0)    
00186 #define RNODE_O2_DHT        (1 << 1)    
00187 #define RNODE_O2_IPv6       (1 << 2)    
00188 #define RNODE_O2_BW_LIMIT   (1 << 3)    
00189 #define RNODE_O2_GNET_FC    (1 << 4)    
00190 #define RNODE_O2_HOPS_FC    (1 << 5)    
00191 #define RNODE_O2_HTTP_HEAD  (1 << 6)    
00192 #define RNODE_O2_ALIVE      (1 << 7)    
00193 #define RNODE_O2_PONG_CACHE (1 << 8)    
00194 #define RNODE_O2_DUP_TTL    (1 << 9)    
00195 #define RNODE_O2_DYN_HITS   (1 << 10)   
00196 #define RNODE_O2_LEAF_GUIDE (1 << 11)   
00197 #define RNODE_O2_OOQ_CHUNK  (1 << 12)   
00199 /*
00200  * XXX this structure should really be inlined in a node,
00201  * XXX to avoid definition duplication --RAM, 2004-08-21
00202  */
00203 
00204 typedef struct gnet_node_status {
00205     guchar status;              
00207     /* FIXME: the variables below should go to gnet_node_info since they
00208      *        only change very seldom
00209      */
00210     time_t connect_date;    
00211     time_t up_date;         
00212     guint32 gnet_files_count;   
00213     guint32 gnet_kbytes_count;  
00214     gboolean gnet_info_known;   
00216     guint32  sent;              
00217     guint32  received;          
00218     guint32  tx_dropped;        
00219     guint32  rx_dropped;        
00220     guint32  n_bad;             
00221     guint16  n_dups;            
00222     guint16  n_hard_ttl;        
00223     guint32  n_weird;           
00224     guint32  n_hostile;         
00225     guint32  n_spam;            
00226     guint32  n_evil;            
00228     gint     squeue_sent;
00229     gint     squeue_count;
00230     gint     mqueue_count;
00231     gint     mqueue_percent_used;
00232     gboolean in_tx_flow_control;
00233     gboolean in_tx_swift_control;
00234 
00235     /*
00236      * Traffic statistics -- RAM, 13/05/2002.
00237      */
00238 
00239     gint32   tx_given;          
00240     gint32   tx_deflated;       
00241     gint32   tx_written;        
00242     gboolean tx_compressed;     
00243     gfloat   tx_compression_ratio; 
00244     guint32  tx_bps;            
00246     gint32   rx_given;          
00247     gint32   rx_inflated;       
00248     gint32   rx_read;           
00249     gboolean rx_compressed;     
00250     gfloat   rx_compression_ratio;
00251     gfloat   rx_bps;            
00253     /*
00254      * Gnutella statistics -- RAM, 10/12/2003.
00255      */
00256 
00257     gboolean has_qrp;       
00258     gfloat qrp_efficiency;  
00259     guint32 rx_queries;     
00260     guint32 tx_queries;     
00261     guint32 rx_qhits;       
00262     guint32 tx_qhits;       
00264     gint qrt_slots;         
00265     gint qrt_generation;    
00266     gint qrt_fill_ratio;    
00267     gint qrt_pass_throw;    
00269     guint32  rt_avg;            
00270     guint32  rt_last;           
00272     guint32 tcp_rtt;            
00273     guint32 udp_rtt;            
00275     gint     shutdown_remain;   
00276     gchar    message[128];      
00277 } gnet_node_status_t;
00278 
00279 typedef struct gnet_node_info {
00280     node_id_t node_id;      
00282     gchar gnet_guid[GUID_RAW_SIZE];     
00284     gchar *error_str;       
00285     const gchar *vendor;    
00287     gint proto_major;       
00288     gint proto_minor;       
00289     vendor_code_t vcode;    
00290     gboolean is_pseudo;     
00292     host_addr_t addr;       
00293     host_addr_t gnet_addr;  
00295     guint16 port;           
00296     guint16 gnet_port;      
00297     guint16 country;        
00299 } gnet_node_info_t;
00300 
00301 /*
00302  * Peer modes.
00303  */
00304 
00305 typedef enum {
00306     NODE_P_LEAF = 0,            
00307     NODE_P_AUTO,                
00308     NODE_P_ULTRA,               
00309     NODE_P_NORMAL,              
00310     NODE_P_CRAWLER,             
00311     NODE_P_UDP,                 
00312     NODE_P_UNKNOWN              
00313 } node_peer_t;
00314 
00315 /*
00316  * QRT state.
00317  */
00318 
00319 typedef enum {
00320     QRT_S_NONE = 0,             
00321     QRT_S_SENDING,              
00322     QRT_S_SENT,                 
00323     QRT_S_RECEIVING,            
00324     QRT_S_PATCHING,             
00325     QRT_S_RECEIVED              
00326 } qrt_state_t;
00327 
00328 typedef struct gnet_node_flags {
00329     node_peer_t peermode;
00330     qrt_state_t qrt_state;
00331     qrt_state_t uqrt_state;
00332     guint8 hops_flow;
00333     gboolean incoming;
00334     gboolean writable;
00335     gboolean readable;
00336     gboolean tx_compressed;
00337     gboolean rx_compressed;
00338     gboolean mqueue_empty;
00339     gboolean mqueue_above_lowat;
00340     gboolean in_tx_flow_control;
00341     gboolean in_tx_swift_control;
00342     gboolean is_push_proxied;
00343     gboolean is_proxying;
00344     gboolean tls;
00345 } gnet_node_flags_t;
00346 
00347 /*
00348  * Node states.
00349  */
00350 typedef enum {
00351     GTA_NODE_CONNECTING         = 1,    
00352     GTA_NODE_HELLO_SENT         = 2,    
00353     GTA_NODE_WELCOME_SENT       = 3,    
00354     GTA_NODE_CONNECTED          = 4,    
00355     GTA_NODE_REMOVING           = 5,    
00356     GTA_NODE_RECEIVING_HELLO    = 6,    
00357     GTA_NODE_SHUTDOWN           = 7     
00359 } gnet_node_state_t;
00360 
00361 #define GTA_NORMAL_TTL              4   
00363 /*
00364  * Nodes callback definitions
00365  */
00366 typedef void (*node_added_listener_t) (node_id_t);
00367 typedef void (*node_removed_listener_t) (node_id_t);
00368 typedef void (*node_info_changed_listener_t) (node_id_t);
00369 typedef void (*node_flags_changed_listener_t) (node_id_t);
00370 
00371 #define node_add_listener(signal, callback) \
00372     CAT3(node_add_,signal,_listener)(callback);
00373 
00374 #define node_remove_listener(signal, callback) \
00375     CAT3(node_remove_,signal,_listener)(callback);
00376 
00377 #ifdef CORE_SOURCES
00378 
00379 /***
00380  *** Gnet nodes
00381  ***/
00382 
00383 void node_add_node_added_listener(node_added_listener_t);
00384 void node_remove_node_added_listener(node_added_listener_t);
00385 void node_add_node_removed_listener(node_removed_listener_t);
00386 void node_remove_node_removed_listener(node_removed_listener_t);
00387 void node_add_node_info_changed_listener(node_info_changed_listener_t);
00388 void node_remove_node_info_changed_listener(node_info_changed_listener_t);
00389 void node_add_node_flags_changed_listener(node_flags_changed_listener_t);
00390 void node_remove_node_flags_changed_listener(node_flags_changed_listener_t);
00391 
00392 /*
00393  * Nodes public interface
00394  */
00395 void node_add(const host_addr_t addr, guint16, guint32 flags);
00396 void node_add_by_name(const gchar *host, guint16, guint32 flags);
00397 void node_remove_by_id(const node_id_t node_id);
00398 void node_remove_nodes_by_id(const GSList *node_list);
00399 gboolean node_get_status(const node_id_t node_id, gnet_node_status_t *s);
00400 gnet_node_info_t *node_get_info(const node_id_t node_id);
00401 void node_clear_info(gnet_node_info_t *info);
00402 void node_free_info(gnet_node_info_t *info);
00403 gboolean node_fill_flags(const node_id_t node_id, gnet_node_flags_t *flags);
00404 gboolean node_fill_info(const node_id_t node_id, gnet_node_info_t *info);
00405 const gchar *node_flags_to_string(const gnet_node_flags_t *flags);
00406 const gchar *node_peermode_to_string(node_peer_t m);
00407 
00408 
00409 #endif /* CORE_SOURCES */
00410 
00411 #endif /* _if_core_nodes_h */
00412 /* vi: set ts=4 sw=4 cindent: */

Generated on Sat Jun 30 17:53:23 2007 for gtk-gnutella by  doxygen 1.3.9.1