Definition in file peer.h.
#include "utils.h"
#include "config.h"
#include <sys/types.h>
Go to the source code of this file.
Data Structures | |
| struct | _peer_t |
| Peer data structure. More... | |
Typedefs | |
| typedef _peer_t | peer |
| Peer data structure. | |
Enumerations | |
| enum | peer_state_t { Closed = 0, Wait_Conn_Ack = 1, Wait_I_CEA = 2, Wait_Conn_Ack_Elect = 3, Wait_Returns = 4, R_Open = 5, I_Open = 6, Closing = 7 } |
| Peer states definition. More... | |
| enum | peer_event_t { Start = 101, Stop = 102, Timeout = 103, Win_Election = 104, R_Conn_CER = 105, I_Rcv_Conn_Ack = 106, I_Rcv_Conn_NAck = 107, I_Rcv_CER = 108, I_Rcv_CEA = 109, R_Rcv_CER = 110, R_Rcv_CEA = 111, I_Rcv_Non_CEA = 112, I_Rcv_DPR = 113, I_Rcv_DPA = 114, R_Rcv_DPR = 115, R_Rcv_DPA = 116, I_Rcv_DWR = 117, I_Rcv_DWA = 118, R_Rcv_DWR = 119, R_Rcv_DWA = 120, Send_Message = 121, I_Rcv_Message = 122, R_Rcv_Message = 123, I_Peer_Disc = 124, R_Peer_Disc = 125 } |
| Peer events definition. More... | |
Functions | |
| peer * | new_peer (str fqdn, str realm, int port) |
| Create a new peer. | |
| void | free_peer (peer *x, int locked) |
| Frees the memory taken by a peer structure. | |
| void | touch_peer (peer *p) |
| "Touches" the peer by updating the last activity time to the current time. | |
| enum peer_state_t |
Peer states definition.
Definition at line 67 of file peer.h.
00067 { 00068 Closed = 0, 00069 Wait_Conn_Ack = 1, 00070 Wait_I_CEA = 2, 00071 Wait_Conn_Ack_Elect = 3, 00072 Wait_Returns = 4, 00073 R_Open = 5, 00074 I_Open = 6, 00075 Closing = 7 00076 } peer_state_t;
| enum peer_event_t |
Peer events definition.
Definition at line 80 of file peer.h.
00080 { 00081 Start = 101, 00082 Stop = 102, 00083 Timeout = 103, 00084 Win_Election = 104, 00085 R_Conn_CER = 105, 00086 I_Rcv_Conn_Ack = 106, 00087 I_Rcv_Conn_NAck = 107, 00088 I_Rcv_CER = 108, 00089 I_Rcv_CEA = 109, 00090 R_Rcv_CER = 110, 00091 R_Rcv_CEA = 111, 00092 I_Rcv_Non_CEA = 112, 00093 I_Rcv_DPR = 113, 00094 I_Rcv_DPA = 114, 00095 R_Rcv_DPR = 115, 00096 R_Rcv_DPA = 116, 00097 I_Rcv_DWR = 117, 00098 I_Rcv_DWA = 118, 00099 R_Rcv_DWR = 119, 00100 R_Rcv_DWA = 120, 00101 Send_Message = 121, 00102 I_Rcv_Message = 122, 00103 R_Rcv_Message = 123, 00104 I_Peer_Disc = 124, 00105 R_Peer_Disc = 125 00106 } peer_event_t;
| peer* new_peer | ( | str | fqdn, | |
| str | realm, | |||
| int | port | |||
| ) |
Create a new peer.
| fqdn | - FQDN of the peer | |
| realm | - Realm of the peer | |
| port | - port of the peer to connect to |
Definition at line 68 of file peer.c.
References _peer_t::activity, Closed, _peer_t::fqdn, _peer_t::I_sock, _peer_t::lock, LOG_NO_MEM, _peer_t::next, _peer_t::port, _peer_t::prev, _peer_t::R_sock, _peer_t::realm, shm_str_dup, and _peer_t::state.
Referenced by get_peer_from_fqdn(), and peer_manager_init().
00069 { 00070 peer *x; 00071 x = shm_malloc(sizeof(peer)); 00072 if (!x){ 00073 LOG_NO_MEM("shm",sizeof(peer)); 00074 goto error; 00075 } 00076 memset(x,0,sizeof(peer)); 00077 shm_str_dup(x->fqdn,fqdn); 00078 if (!x->fqdn.s) goto error; 00079 shm_str_dup(x->realm,realm); 00080 if (!x->realm.s) goto error; 00081 x->port = port; 00082 x->lock = lock_alloc(); 00083 x->lock = lock_init(x->lock); 00084 00085 x->state = Closed; 00086 00087 x->I_sock = -1; 00088 x->R_sock = -1; 00089 00090 x->activity = time(0)-500; 00091 00092 x->next = 0; 00093 x->prev = 0; 00094 00095 return x; 00096 error: 00097 return 0; 00098 }
| void free_peer | ( | peer * | x, | |
| int | locked | |||
| ) |
Frees the memory taken by a peer structure.
| x | - the peer to free | |
| locked | - if the caller of this function already acquired the lock on this peer |
Definition at line 105 of file peer.c.
References _peer_t::fqdn, _peer_t::lock, and _peer_t::realm.
Referenced by peer_manager_destroy(), and peer_timer().
00106 { 00107 if (!x) return; 00108 if (!locked) lock_get(x->lock); 00109 if (x->fqdn.s) shm_free(x->fqdn.s); 00110 if (x->realm.s) shm_free(x->realm.s); 00111 lock_destroy(x->lock); 00112 lock_dealloc((void*)x->lock); 00113 shm_free(x); 00114 }
| void touch_peer | ( | peer * | p | ) | [inline] |
"Touches" the peer by updating the last activity time to the current time.
| p | - which peer to touch |
Definition at line 120 of file peer.c.
References _peer_t::activity.
Referenced by get_peer_from_fqdn(), peer_timer(), R_Accept(), receive_message(), and Snd_Message().
00121 { 00122 p->activity = time(0); 00123 }
1.5.2