Show paths as active or preferred in listpeers.

This commit is contained in:
Adam Ierymenko 2015-12-17 11:03:39 -08:00
parent 2160164e8c
commit aa39b0dc24
2 changed files with 9 additions and 6 deletions

View File

@ -266,6 +266,9 @@ public:
return (p - startAt); return (p - startAt);
} }
inline bool operator==(const Path &p) const { return ((p._addr == _addr)&&(p._localAddress == _localAddress)); }
inline bool operator!=(const Path &p) const { return ((p._addr != _addr)||(p._localAddress != _localAddress)); }
private: private:
uint64_t _lastSend; uint64_t _lastSend;
uint64_t _lastReceived; uint64_t _lastReceived;

12
one.cpp
View File

@ -366,8 +366,8 @@ static int cli(int argc,char **argv)
const char *paddr = (const char *)0; const char *paddr = (const char *)0;
int64_t lastSend = 0; int64_t lastSend = 0;
int64_t lastReceive = 0; int64_t lastReceive = 0;
bool fixed = false; bool preferred = false;
bool active = false; // fixed/active/inactive bool active = false;
for(unsigned int kk=0;kk<jpath->u.object.length;++kk) { for(unsigned int kk=0;kk<jpath->u.object.length;++kk) {
if ((!strcmp(jpath->u.object.values[kk].name,"address"))&&(jpath->u.object.values[kk].value->type == json_string)) if ((!strcmp(jpath->u.object.values[kk].name,"address"))&&(jpath->u.object.values[kk].value->type == json_string))
paddr = jpath->u.object.values[kk].value->u.string.ptr; paddr = jpath->u.object.values[kk].value->u.string.ptr;
@ -375,12 +375,12 @@ static int cli(int argc,char **argv)
lastSend = jpath->u.object.values[kk].value->u.integer; lastSend = jpath->u.object.values[kk].value->u.integer;
else if ((!strcmp(jpath->u.object.values[kk].name,"lastReceive"))&&(jpath->u.object.values[kk].value->type == json_integer)) else if ((!strcmp(jpath->u.object.values[kk].name,"lastReceive"))&&(jpath->u.object.values[kk].value->type == json_integer))
lastReceive = jpath->u.object.values[kk].value->u.integer; lastReceive = jpath->u.object.values[kk].value->u.integer;
else if ((!strcmp(jpath->u.object.values[kk].name,"fixed"))&&(jpath->u.object.values[kk].value->type == json_boolean)) else if ((!strcmp(jpath->u.object.values[kk].name,"preferred"))&&(jpath->u.object.values[kk].value->type == json_boolean))
fixed = (jpath->u.object.values[kk].value->u.boolean != 0); preferred = (jpath->u.object.values[kk].value->u.boolean != 0);
else if ((!strcmp(jpath->u.object.values[kk].name,"active"))&&(jpath->u.object.values[kk].value->type == json_boolean)) else if ((!strcmp(jpath->u.object.values[kk].name,"active"))&&(jpath->u.object.values[kk].value->type == json_boolean))
active = (jpath->u.object.values[kk].value->u.boolean != 0); active = (jpath->u.object.values[kk].value->u.boolean != 0);
} }
if ((paddr)&&((active)||(fixed))) { if ((paddr)&&(active)) {
int64_t now = (int64_t)OSUtils::now(); int64_t now = (int64_t)OSUtils::now();
if (lastSend > 0) if (lastSend > 0)
lastSend = now - lastSend; lastSend = now - lastSend;
@ -391,7 +391,7 @@ static int cli(int argc,char **argv)
paddr, paddr,
lastSend, lastSend,
lastReceive, lastReceive,
(fixed ? "fixed" : (active ? "active" : "inactive"))); (preferred ? "preferred" : "active"));
if (paths.length()) if (paths.length())
paths.push_back(','); paths.push_back(',');
paths.append(pathtmp); paths.append(pathtmp);