| 77 | } |
| 78 | |
| 79 | void server_loop(RNS::Destination& destination) { |
| 80 | // Let the user know that everything is ready |
| 81 | RNS::logf(RNS::LOG_NOTICE, "Link example <%s> running, waiting for a connection.", destination.hash().toHex().c_str()); |
| 82 | |
| 83 | RNS::log("Hit enter to manually send an announce (Ctrl-C to quit)"); |
| 84 | |
| 85 | // We enter a loop that runs until the users exits. |
| 86 | // If the user hits enter, we will announce our server |
| 87 | // destination on the network, which will let clients |
| 88 | // know how to create messages directed towards it. |
| 89 | while (true) { |
| 90 | reticulum.loop(); |
| 91 | // Non-blocking input |
| 92 | char ch; |
| 93 | while (read(STDIN_FILENO, &ch, 1) > 0) { |
| 94 | if (ch == '\n') { |
| 95 | destination.announce(); |
| 96 | RNS::logf(RNS::LOG_NOTICE, "Sent announce from %s", destination.hash().toHex().c_str()); |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | // This initialisation is executed when the users chooses |
| 103 | // to run as a server |