1 : /*
2 : * peerlist.h - Teredo relay internal peers list declaration
3 : * $Id: peerlist.h 1834 2006-12-12 17:28:54Z remi $
4 : */
5 :
6 : /***********************************************************************
7 : * Copyright © 2004-2006 Rémi Denis-Courmont. *
8 : * This program is free software; you can redistribute and/or modify *
9 : * it under the terms of the GNU General Public License as published *
10 : * by the Free Software Foundation; version 2 of the license. *
11 : * *
12 : * This program is distributed in the hope that it will be useful, *
13 : * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
15 : * See the GNU General Public License for more details. *
16 : * *
17 : * You should have received a copy of the GNU General Public License *
18 : * along with this program; if not, you can get it from: *
19 : * http://www.gnu.org/copyleft/gpl.html *
20 : ***********************************************************************/
21 :
22 : #ifndef LIBTEREDO_PEERLIST_H
23 : # define LIBTEREDO_PEERLIST_H
24 :
25 : # define TEREDO_TIMEOUT 30 // seconds
26 : # define MAXQUEUE 1280u // bytes
27 :
28 : typedef struct teredo_queue teredo_queue;
29 :
30 : typedef struct teredo_peer
31 : {
32 : teredo_queue *queue;
33 : size_t queue_left;
34 : teredo_clock_t last_rx;
35 : teredo_clock_t last_tx;
36 : uint32_t mapped_addr;
37 : uint16_t mapped_port;
38 : unsigned trusted:1;
39 : unsigned bubbles:3;
40 : unsigned pings:3;
41 : unsigned last_ping:9;
42 : } teredo_peer;
43 :
44 :
45 : typedef void (*teredo_dequeue_cb) (void *, const void *, size_t);
46 :
47 : #ifdef __cplusplus
48 : extern "C" {
49 : #endif
50 :
51 : void teredo_enqueue_in (teredo_peer *restrict peer, const void *restrict data,
52 : size_t len, uint32_t ip, uint16_t port);
53 :
54 : void teredo_enqueue_out (teredo_peer *restrict peer,
55 : const void *restrict data, size_t len);
56 : teredo_queue *teredo_peer_queue_yield (teredo_peer *peer);
57 : void teredo_queue_emit (teredo_queue *q, int fd, uint32_t ipv4, uint16_t port,
58 : teredo_dequeue_cb cb, void *r);
59 :
60 : #ifdef __cplusplus
61 : }
62 : #endif
63 :
64 : static inline void SetMapping (teredo_peer *peer, uint32_t ip, uint16_t port)
65 0 : {
66 0 : peer->mapped_addr = ip;
67 0 : peer->mapped_port = port;
68 0 : }
69 :
70 : static inline void TouchReceive (teredo_peer *peer, teredo_clock_t now)
71 0 : {
72 0 : peer->last_rx = now;
73 0 : }
74 :
75 : static inline void TouchTransmit (teredo_peer *peer, teredo_clock_t now)
76 0 : {
77 0 : peer->last_tx = now;
78 0 : }
79 :
80 :
81 : static inline
82 : bool IsValid (const teredo_peer *peer, teredo_clock_t now)
83 0 : {
84 0 : return (now - peer->last_rx) <= 30;
85 : }
86 :
87 :
88 : typedef struct teredo_peerlist teredo_peerlist;
89 :
90 : struct in6_addr;
91 :
92 : # ifdef __cplusplus
93 : extern "C" {
94 : # endif
95 :
96 : teredo_peerlist *teredo_list_create (unsigned max, unsigned expiration);
97 : void teredo_list_destroy (teredo_peerlist *l);
98 : void teredo_list_reset (teredo_peerlist *l, unsigned max);
99 :
100 : teredo_peer *teredo_list_lookup (teredo_peerlist *restrict list,
101 : const struct in6_addr *restrict addr,
102 : bool *restrict create);
103 : void teredo_list_release (teredo_peerlist *l);
104 :
105 : # ifdef __cplusplus
106 : }
107 : # endif
108 :
109 :
110 : #endif /* ifndef LIBTEREDO_PEERLIST_H */
|