|
51 | 51 |
|
52 | 52 | #define RESP_SERVER_LOGIN_OK 0 // response to ANON_REQ |
53 | 53 |
|
| 54 | +#define ANON_REQ_TYPE_REGIONS 0x01 |
| 55 | + |
54 | 56 | #define CLI_REPLY_DELAY_MILLIS 600 |
55 | 57 |
|
56 | 58 | #define LAZY_CONTACTS_WRITE_DELAY 5000 |
@@ -139,6 +141,19 @@ uint8_t MyMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t* secr |
139 | 141 | return 13; // reply length |
140 | 142 | } |
141 | 143 |
|
| 144 | +uint8_t MyMesh::handleAnonRegionsReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data) { |
| 145 | + // REVISIT: should there be params like 'since' in request data[] ? |
| 146 | + if (regions_limiter.allow(rtc_clock.getCurrentTime())) { |
| 147 | + memcpy(reply_data, &sender_timestamp, 4); // prefix with sender_timestamp, like a tag |
| 148 | + |
| 149 | + uint32_t now = getRTCClock()->getCurrentTime(); |
| 150 | + memcpy(&reply_data[4], &now, 4); // include our clock (for easy clock sync, if this is a trusted node) |
| 151 | + |
| 152 | + return 8 + region_map.exportNamesTo((char *) &reply_data[8], sizeof(reply_data) - 12, REGION_DENY_FLOOD); // reply length |
| 153 | + } |
| 154 | + return 0; |
| 155 | +} |
| 156 | + |
142 | 157 | int MyMesh::handleRequest(ClientInfo *sender, uint32_t sender_timestamp, uint8_t *payload, size_t payload_len) { |
143 | 158 | // uint32_t now = getRTCClock()->getCurrentTimeUnique(); |
144 | 159 | // memcpy(reply_data, &now, 4); // response packets always prefixed with timestamp |
@@ -450,8 +465,8 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m |
450 | 465 | uint8_t reply_len; |
451 | 466 | if (data[4] == 0 || data[4] >= ' ') { // is password, ie. a login request |
452 | 467 | reply_len = handleLoginReq(sender, secret, timestamp, &data[4], packet->isRouteFlood()); |
453 | | - //} else if (data[4] == ANON_REQ_TYPE_*) { // future type codes |
454 | | - // TODO |
| 468 | + } else if (data[4] == ANON_REQ_TYPE_REGIONS) { |
| 469 | + reply_len = handleAnonRegionsReq(sender, timestamp, &data[5]); |
455 | 470 | } else { |
456 | 471 | reply_len = 0; // unknown request type |
457 | 472 | } |
@@ -668,7 +683,8 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc |
668 | 683 | mesh::RTCClock &rtc, mesh::MeshTables &tables) |
669 | 684 | : mesh::Mesh(radio, ms, rng, rtc, *new StaticPoolPacketManager(32), tables), |
670 | 685 | _cli(board, rtc, sensors, &_prefs, this), telemetry(MAX_PACKET_PAYLOAD - 4), region_map(key_store), temp_map(key_store), |
671 | | - discover_limiter(4, 120) // max 4 every 2 minutes |
| 686 | + discover_limiter(4, 120), // max 4 every 2 minutes |
| 687 | + regions_limiter(4, 180) // max 4 every 3 minutes |
672 | 688 | #if defined(WITH_RS232_BRIDGE) |
673 | 689 | , bridge(&_prefs, WITH_RS232_BRIDGE, _mgr, &rtc) |
674 | 690 | #endif |
|
0 commit comments