This repository was archived by the owner on Jul 9, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +38
-4
lines changed Expand file tree Collapse file tree 2 files changed +38
-4
lines changed Original file line number Diff line number Diff line change 1
1
#include " Husarnet.h"
2
2
#include < cassert>
3
3
4
+
4
5
_Husarnet Husarnet;
5
6
6
7
extern " C" {
7
8
void husarnet_start ();
8
9
void husarnet_join (const char * joinCode, const char * hostname);
9
10
void husarnet_retrieve_license (const char * hostname);
11
+ const char * husarnet_get_hostname ();
10
12
}
11
13
14
+ struct InternalIP6Address {
15
+ std::array<uint8_t , 16 > data;
16
+ };
17
+
18
+ extern std::vector<std::pair<InternalIP6Address, std::string>> husarnet_hosts;
19
+
12
20
static bool alreadyStarted = false ;
13
21
14
22
void _Husarnet::selfHostedSetup (const char * hostname) {
@@ -26,3 +34,18 @@ void _Husarnet::join(const char* joinCode, const char* hostname) {
26
34
assert (!alreadyStarted);
27
35
husarnet_join (joinCode, hostname);
28
36
}
37
+
38
+ typedef std::pair<IPv6Address, String> hostPair;
39
+ std::vector<hostPair> _Husarnet::listPeers () {
40
+ std::vector<hostPair> peers;
41
+
42
+ for (auto const & host: husarnet_hosts) {
43
+ peers.push_back (hostPair (IPv6Address (host.first .data .data ()), String (host.second .c_str ())));
44
+ }
45
+
46
+ return peers;
47
+ }
48
+
49
+ String _Husarnet::getHostname () {
50
+ return String (husarnet_get_hostname ());
51
+ }
Original file line number Diff line number Diff line change 3
3
4
4
#include " Arduino.h"
5
5
#include " HusarnetServer.h"
6
- //#include <freertos/task.h>
6
+ #include " IPv6Address.h"
7
+ #include " WString.h"
8
+ #include < vector>
9
+ #include < utility>
10
+ #include < string>
7
11
8
- struct _Husarnet {
12
+ struct _Husarnet
13
+ {
9
14
// Sets up Husarnet to use self-hosted base server
10
- void selfHostedSetup (const char * hostname );
15
+ void selfHostedSetup (const char * hostname);
11
16
12
17
// Starts the Husarnet
13
18
void start ();
14
19
15
20
// Provides join code. Use before Husarnet.start().
16
- void join (const char * joinCode , const char * hostname = "");
21
+ void join (const char *joinCode, const char *hostname = " " );
22
+
23
+ // Get list of peers' hostnames and addresses
24
+ std::vector<std::pair<IPv6Address, String>> listPeers ();
25
+
26
+ // Get hostname you're currently known at
27
+ String getHostname ();
17
28
};
18
29
19
30
extern _Husarnet Husarnet;
You can’t perform that action at this time.
0 commit comments