forked from ZmnSCPxj/clboss
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert ListpeerResult to use ConstructedListpeers
Construct a "compatibility struct" to convert `listpeerchannels` output into legacy `listpeers` format. Tests written using the legacy listpeers format can use the `convert_legacy_listpeers` utility to construct a compatibility struct. The test_peerjudge_datagatherer malformed test needed to be malformed differently to achieve the desired effect.
- Loading branch information
Showing
17 changed files
with
230 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include"Boss/Mod/ConstructedListpeers.hpp" | ||
#include"Jsmn/Object.hpp" | ||
#include<sstream> | ||
|
||
namespace Boss { namespace Mod { | ||
|
||
/* | ||
* IMPORTANT - the msg is no longer directly obtained from | ||
* `listpeers` but rather is constructed by "convolving" the value | ||
* from `listpeerchannels`. Specifically, the top level `peer` | ||
* objects are non-standard and only have what CLBOSS uses ... | ||
*/ | ||
|
||
/* This helper is used by tests which use the old listpeers format */ | ||
Boss::Mod::ConstructedListpeers convert_legacy_listpeers(Jsmn::Object const & legacy_listpeers) { | ||
Boss::Mod::ConstructedListpeers cpeers; | ||
for (auto p : legacy_listpeers) { | ||
if (!p.has("id")) | ||
continue; | ||
auto id = Ln::NodeId(std::string(p["id"])); | ||
cpeers[id].connected = false; | ||
if (p.has("connected")) { | ||
auto connected = p["connected"]; | ||
cpeers[id].connected = connected.is_boolean() && bool(connected); | ||
} | ||
auto cs = p["channels"]; | ||
for (auto c : cs) { | ||
cpeers[id].channels.push_back(c); | ||
} | ||
} | ||
return cpeers; | ||
} | ||
|
||
std::ostream& operator<<(std::ostream& os, Boss::Mod::ConstructedListpeers const& o) { | ||
for (auto p : o) { | ||
os << p.first << ':' | ||
<< "connected: " << p.second.connected | ||
<< ", channels: "; | ||
for (auto c : p.second.channels) { | ||
os << c; | ||
} | ||
} | ||
return os; | ||
} | ||
|
||
|
||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef BOSS_MOD_CONSTRUCTEDLISTPEERS_HPP | ||
#define BOSS_MOD_CONSTRUCTEDLISTPEERS_HPP | ||
|
||
#include<map> | ||
#include"Ln/NodeId.hpp" | ||
#include"Jsmn/Object.hpp" | ||
|
||
namespace Boss { namespace Mod { | ||
|
||
/* | ||
* IMPORTANT - the msg is no longer directly obtained from | ||
* `listpeers` but rather is constructed by "convolving" the value | ||
* from `listpeerchannels`. Specifically, the top level `peer` | ||
* objects are non-standard and only have what CLBOSS uses ... | ||
*/ | ||
|
||
/** class Boss::Mod::ConstructedListpeers | ||
*/ | ||
struct ConstructedListpeer { | ||
bool connected; | ||
std::vector<Jsmn::Object> channels; | ||
}; | ||
|
||
typedef std::map<Ln::NodeId, ConstructedListpeer> ConstructedListpeers; | ||
|
||
std::ostream& operator<<(std::ostream& os, ConstructedListpeers const& o); | ||
|
||
|
||
/* for unit tests w/ legacy listpeer setups */ | ||
Boss::Mod::ConstructedListpeers convert_legacy_listpeers(Jsmn::Object const & legacy_listpeers); | ||
|
||
}} | ||
#endif /* !defined(BOSS_MOD_CONSTRUCTEDLISTPEERS_HPP) */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.