MCPcopy Create free account
hub / github.com/attermann/microReticulum / server

Function server

examples/nomadnet/src/main.cpp:139–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137}
138
139void server() {
140
141 // Randomly generate a fresh identity for this example run.
142 RNS::Identity server_identity = RNS::Identity();
143
144 // Create an IN/SINGLE destination on the NomadNet aspect, so
145 // clients (this example, or a Python NomadNet browser) can find
146 // us by aspect/announce and open a Link.
147 RNS::Destination server_destination = RNS::Destination(
148 server_identity,
149 RNS::Type::Destination::IN,
150 RNS::Type::Destination::SINGLE,
151 APP_NAME,
152 APP_ASPECT
153 );
154
155 // Logging-only — not strictly required for request/response to work.
156 server_destination.set_link_established_callback(server_link_established);
157
158 // Register the page handler. ALLOW_ALL because page browsing is open
159 // to anyone who can reach the node, just like a Python NomadNet
160 // node's default policy.
161 server_destination.register_request_handler(
162 RNS::Bytes(DEFAULT_PAGE_PATH),
163 serve_index,
164 RNS::Type::Destination::ALLOW_ALL
165 );
166
167 // Announce once at startup so a client that's already listening can
168 // discover us immediately. The node name is sent as the announce
169 // app_data (plain UTF-8 bytes), matching nomadnet/Node.py:217-222 —
170 // this is what other NomadNet clients show in their site listing.
171 const RNS::Bytes node_name_app_data(NODE_NAME);
172 server_destination.announce(node_name_app_data);
173 RNS::logf(RNS::LOG_NOTICE, "Sent startup announce from %s as \"%s\"",
174 server_destination.hash().toHex().c_str(), NODE_NAME);
175
176 server_loop(server_destination);
177}
178
179
180/*

Callers 1

mainFunction · 0.70

Calls 10

BytesClass · 0.85
logfFunction · 0.85
announceMethod · 0.80
toHexMethod · 0.80
hashMethod · 0.80
server_loopFunction · 0.70
IdentityClass · 0.50
DestinationClass · 0.50

Tested by

no test coverage detected