15 lnkTbl =
new LinkInfo[
maxLnk+1];
16 links =
new UiSetPair(
maxLnk);
17 ht =
new UiHashTbl(
maxLnk);
23 delete [] lnkTbl;
delete links;
delete ht;
delete padrMap;
35 if (lnk == 0) lnk = links->firstOut();
36 if (lnk == 0 || !links->isOut(lnk))
return 0;
37 if (peerIp != 0 && peerPort != 0) {
38 if (ht->lookup(
hashkey(peerIp, peerPort)) != 0)
return 0;
39 if (!ht->insert(
hashkey(peerIp, peerPort),lnk))
return 0;
41 if (ht->lookup(nonce) != 0)
return 0;
42 if (!ht->insert(nonce,lnk))
return 0;
45 lnkTbl[lnk].peerIp = peerIp;
46 lnkTbl[lnk].peerPort = peerPort;
47 lnkTbl[lnk].nonce = nonce;
48 lnkTbl[lnk].peerAdr = 0;
50 setPeerType(lnk,Forest::UNDEF_NODE);
55 lnkTbl[lnk].comtSet =
new set<int>();
65 if (!links->isIn(lnk))
return false;
66 if (ht->lookup(lnkTbl[lnk].nonce) != lnk)
return false;
67 ht->remove(lnkTbl[lnk].nonce);
68 if (!ht->insert(
hashkey(peerIp, peerPort),lnk)) {
69 ht->insert(lnkTbl[lnk].nonce,lnk);
return false;
71 lnkTbl[lnk].peerIp = peerIp;
72 lnkTbl[lnk].peerPort = peerPort;
80 if (!links->isIn(lnk))
return false;
81 ipa_t peerIp = lnkTbl[lnk].peerIp;
82 ipp_t peerPort = lnkTbl[lnk].peerPort;
83 if (ht->lookup(
hashkey(peerIp, peerPort)) != lnk)
return false;
84 ht->remove(
hashkey(peerIp, peerPort));
85 if (!ht->insert(lnkTbl[lnk].nonce,lnk)) {
86 ht->insert(
hashkey(peerIp, peerPort),lnk);
89 lnkTbl[lnk].peerIp = 0;
90 lnkTbl[lnk].peerPort = 0;
116 if (!
valid(lnk))
return;
118 uint64_t x = lnkTbl[lnk].peerAdr; x <<= 32;
119 x |= lnkTbl[lnk].peerAdr;
123 uint64_t x = adr; x <<= 32; x |= adr;
126 lnkTbl[lnk].peerAdr = adr;
134 if (!links->isIn(lnk))
return;
135 ht->remove(
hashkey(getPeerIpAdr(lnk),getPeerPort(lnk)));
136 delete lnkTbl[lnk].comtSet;
174 int lnk, iface; RateSpec rs;
175 ipa_t peerIp; ipp_t peerPort;
191 peerType = Forest::getNodeType(typStr);
192 if (peerType == Forest::UNDEF_NODE)
return 0;
194 if (!
addEntry(lnk,peerIp,peerPort,0))
return 0;
196 setPeerType(lnk, peerType);
198 getRates(lnk) = rs; getAvailRates(lnk) = rs;
220 for (
int i = 1; i <= num; i++) {
222 cerr <<
"LinkTable::read: could not read "
223 << i <<
"-th table entry" << endl;
236 if (!
valid(lnk)) { s =
"";
return s; }
238 ss << setw(5) << right << lnk << setw(6) << getIface(lnk) <<
" ";
241 <<
":" << setw(5) << left << getPeerPort(lnk) <<
" ";
242 ss << setw(10) << left << Forest::nodeType2string(getPeerType(lnk),s);
244 ss <<
" " << getRates(lnk).toString(s);
245 ss <<
" " << getAvailRates(lnk).toString(s);
246 ss <<
" " << lnkTbl[lnk].comtCount;
257 ss << links->getNumIn() << endl;
258 ss <<
"# link iface peerIp:port peerType peerAdr ";
259 ss <<
" rates avail rates comtree count\n";
266 #define pack8(x) (*buf = *((char*) x), buf += 1)
267 #define pack16(x) (*buf = *((char*) htons(x)), buf += sizeof(uint16_t))
268 #define pack32(x) (*buf = *((char*) htonl(x)), buf += sizeof(uint32_t))
269 #define pack64(x) ( pack32(((x)>>32)&0xffffffff), pack32((x)&0xffffffff))
270 #define packRspec(x) ( pack32(x.bitRateUp), pack32(x.bitRateDown), \
271 pack32(x.pktRateUp), pack32(x.pktRateDown) )
278 if (!
valid(lnk))
return 0;
280 pack32(lnkTbl[lnk].iface);
282 pack32(lnkTbl[lnk].peerIp);
283 pack16(lnkTbl[lnk].peerPort);
284 uint16_t x = lnkTbl[lnk].peerType; pack16(x);
285 pack16(lnkTbl[lnk].peerType);
286 pack32(lnkTbl[lnk].peerAdr);
288 pack8(lnkTbl[lnk].status);
289 pack64(lnkTbl[lnk].nonce);
291 packRspec(lnkTbl[lnk].rates);
292 packRspec(lnkTbl[lnk].availRates);
294 pack32(lnkTbl[lnk].comtCount);
298 #define unpack8(x) (x = *buf, buf += 1)
299 #define unpack16(x) (x = ntohs(*((uint16_t*) buf)), buf += sizeof(uint16_t))
300 #define unpack32(x) (x = ntohl(*((uint32_t*) buf)), buf += sizeof(uint32_t))
301 #define unpack64(x) (x = ntohl(*((uint32_t*) buf)), buf += sizeof(uint32_t), \
302 x |= ntohl(*((uint32_t*) buf)), buf += sizeof(uint32_t))
303 #define unpackRspec(x) (pack32(x.bitRateUp), pack32(x.bitRateDown), \
304 pack32(x.pktRateUp), pack32(x.pktRateDown) )
310 if (!
valid(lnk))
return 0;
312 unpack32(lnkTbl[lnk].iface);
314 unpack32(lnkTbl[lnk].peerIp);
315 unpack16(lnkTbl[lnk].peerPort);
316 uint16_t x; unpack16(x); lnkTbl[lnk].peerType = (
Forest::ntyp_t) x;
317 unpack32(lnkTbl[lnk].peerAdr);
319 unpack8(lnkTbl[lnk].status);
320 unpack64(lnkTbl[lnk].nonce);
322 unpackRspec(lnkTbl[lnk].rates);
323 unpackRspec(lnkTbl[lnk].availRates);
325 unpack32(lnkTbl[lnk].comtCount);