Skip to content

Commit 1769146

Browse files
Merge pull request #6 from AnnikaH/master
Sending data about the uplink to mothership
2 parents e4a7db0 + 0a08129 commit 1769146

4 files changed

Lines changed: 31 additions & 3 deletions

File tree

starbase/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ set(SERVICE_NAME "IncludeOS Starbase")
1818
# Name of your service binary
1919
set(BINARY "starbase")
2020

21-
# Maximum memory can be hard-coded into the binary
22-
set(MAX_MEM 128)
23-
2421
# Source files to be linked with OS library parts to form bootable image
2522
set(SOURCES
2623
service.cpp # ...add more here

transport.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ namespace uplink {
3434
APPDATA = 6,
3535
PANIC = 7,
3636
STATS = 8,
37+
UPLINK = 9,
3738
ERROR = 255 // Legacy
3839
};
3940

ws_uplink.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ namespace uplink {
180180
MYINFO("Websocket established");
181181

182182
send_ident();
183+
184+
send_uplink();
183185
}
184186

185187
void WS_uplink::handle_ws_close(uint16_t code)
@@ -393,6 +395,32 @@ namespace uplink {
393395
send_message(Transport_code::IDENT, str.data(), str.size());
394396
}
395397

398+
void WS_uplink::send_uplink() {
399+
MYINFO("Sending uplink");
400+
using namespace rapidjson;
401+
402+
StringBuffer buf;
403+
Writer<StringBuffer> writer{buf};
404+
405+
writer.StartObject();
406+
407+
writer.Key("url");
408+
writer.String(config_.url);
409+
410+
writer.Key("token");
411+
writer.String(config_.token);
412+
413+
writer.EndObject();
414+
415+
std::string str = buf.GetString();
416+
417+
MYINFO("%s", str.c_str());
418+
419+
auto transport = Transport{Header{Transport_code::UPLINK, static_cast<uint32_t>(str.size())}};
420+
transport.load_cargo(str.data(), str.size());
421+
ws_->write(transport.data().data(), transport.data().size());
422+
}
423+
396424
void WS_uplink::send_message(Transport_code code, const char* data, size_t len) {
397425
auto transport = Transport{Header{code, static_cast<uint32_t>(len)}};
398426

ws_uplink.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class WS_uplink {
5353

5454
void send_log(const char*, size_t);
5555

56+
void send_uplink();
57+
5658
void update(const std::vector<char>& buffer);
5759

5860
void send_error(const std::string& err);

0 commit comments

Comments
 (0)