15 lnkTbl =
new LinkInfo[maxLnk+1];
16 links =
new UiSetPair(maxLnk);
17 ht =
new UiHashTbl(maxLnk);
18 padrMap =
new UiHashTbl(maxLnk);
23 delete [] lnkTbl;
delete links;
delete ht;
delete padrMap;
40 if (lnk == 0) lnk = links->firstOut();
41 if (lnk == 0 || !links->isOut(lnk))
return 0;
42 if (ht->lookup(nonce) != 0)
return 0;
43 if (!ht->insert(nonce,lnk))
return 0;
46 lnkTbl[lnk].status =
false;
47 lnkTbl[lnk].peerIp = peerIp;
48 lnkTbl[lnk].peerPort = peerPort;
49 lnkTbl[lnk].nonce = nonce;
50 lnkTbl[lnk].peerAdr = 0;
52 setPeerType(lnk,Forest::UNDEF_NODE);
57 lnkTbl[lnk].comtSet =
new set<int>();
69 if (!links->isIn(lnk) || isConnected(lnk))
return false;
70 if (ht->lookup(lnkTbl[lnk].nonce) != lnk)
return false;
71 ht->remove(lnkTbl[lnk].nonce);
72 if (!ht->insert(
hashkey(peerIp, peerPort),lnk)) {
73 ht->insert(lnkTbl[lnk].nonce,lnk);
return false;
75 lnkTbl[lnk].peerIp = peerIp;
76 lnkTbl[lnk].peerPort = peerPort;
77 lnkTbl[lnk].status =
true;
85 if (!links->isIn(lnk))
return;
86 if (isConnected(lnk)) {
87 ht->remove(
hashkey(getPeerIpAdr(lnk),getPeerPort(lnk)));
89 ht->remove(getNonce(lnk));
91 delete lnkTbl[lnk].comtSet;
100 if (!
valid(lnk))
return;
102 uint64_t x = lnkTbl[lnk].peerAdr; x <<= 32;
103 x |= lnkTbl[lnk].peerAdr;
107 uint64_t x = adr; x <<= 32; x |= adr;
110 lnkTbl[lnk].peerAdr = adr;
147 int lnk, iface; RateSpec rs;
148 ipa_t peerIp; ipp_t peerPort;
164 peerType = Forest::getNodeType(typStr);
165 if (peerType == Forest::UNDEF_NODE)
return 0;
167 if (!
addEntry(lnk,peerIp,peerPort,0))
return 0;
169 setPeerType(lnk, peerType);
171 getRates(lnk) = rs; getAvailRates(lnk) = rs;
193 for (
int i = 1; i <= num; i++) {
195 cerr <<
"LinkTable::read: could not read "
196 << i <<
"-th table entry" << endl;
209 if (!
valid(lnk)) { s =
"";
return s; }
211 ss << setw(5) << right << lnk << setw(6) << getIface(lnk) <<
" ";
214 <<
":" << setw(5) << left << getPeerPort(lnk) <<
" ";
215 ss << setw(10) << left << Forest::nodeType2string(getPeerType(lnk),s);
217 ss <<
" " << getRates(lnk).toString(s);
218 ss <<
" " << getAvailRates(lnk).toString(s);
219 ss <<
" " << lnkTbl[lnk].comtCount;
230 ss << links->getNumIn() << endl;
231 ss <<
"# link iface peerIp:port peerType peerAdr ";
232 ss <<
" rates avail rates comtree count\n";
239 #define pack8(x) (*buf = *((char*) x), buf += 1)
240 #define pack16(x) (*buf = *((char*) htons(x)), buf += sizeof(uint16_t))
241 #define pack32(x) (*buf = *((char*) htonl(x)), buf += sizeof(uint32_t))
242 #define pack64(x) ( pack32(((x)>>32)&0xffffffff), pack32((x)&0xffffffff))
243 #define packRspec(x) ( pack32(x.bitRateUp), pack32(x.bitRateDown), \
244 pack32(x.pktRateUp), pack32(x.pktRateDown) )
251 if (!
valid(lnk))
return 0;
253 pack32(lnkTbl[lnk].iface);
255 pack32(lnkTbl[lnk].peerIp);
256 pack16(lnkTbl[lnk].peerPort);
257 uint16_t x = lnkTbl[lnk].peerType; pack16(x);
258 pack16(lnkTbl[lnk].peerType);
259 pack32(lnkTbl[lnk].peerAdr);
261 pack8(lnkTbl[lnk].status);
262 pack64(lnkTbl[lnk].nonce);
264 packRspec(lnkTbl[lnk].rates);
265 packRspec(lnkTbl[lnk].availRates);
267 pack32(lnkTbl[lnk].comtCount);
271 #define unpack8(x) (x = *buf, buf += 1)
272 #define unpack16(x) (x = ntohs(*((uint16_t*) buf)), buf += sizeof(uint16_t))
273 #define unpack32(x) (x = ntohl(*((uint32_t*) buf)), buf += sizeof(uint32_t))
274 #define unpack64(x) (x = ntohl(*((uint32_t*) buf)), buf += sizeof(uint32_t), \
275 x |= ntohl(*((uint32_t*) buf)), buf += sizeof(uint32_t))
276 #define unpackRspec(x) (pack32(x.bitRateUp), pack32(x.bitRateDown), \
277 pack32(x.pktRateUp), pack32(x.pktRateDown) )
283 if (!
valid(lnk))
return 0;
285 unpack32(lnkTbl[lnk].iface);
287 unpack32(lnkTbl[lnk].peerIp);
288 unpack16(lnkTbl[lnk].peerPort);
289 uint16_t x; unpack16(x); lnkTbl[lnk].peerType = (
Forest::ntyp_t) x;
290 unpack32(lnkTbl[lnk].peerAdr);
292 unpack8(lnkTbl[lnk].status);
293 unpack64(lnkTbl[lnk].nonce);
295 unpackRspec(lnkTbl[lnk].rates);
296 unpackRspec(lnkTbl[lnk].availRates);
298 unpack32(lnkTbl[lnk].comtCount);