Browse Source

Don't busy-poll the snode to get routes to everything discovered by the old pathfinder

Caleb James DeLisle 5 years ago
parent
commit
5edf834119
5 changed files with 22 additions and 8 deletions
  1. 1 0
      dht/Pathfinder.c
  2. 14 6
      net/SessionManager.c
  3. 3 0
      net/SessionManager.h
  4. 1 0
      net/SessionManager_admin.c
  5. 3 2
      wire/RouteHeader.h

+ 1 - 0
dht/Pathfinder.c

@@ -101,6 +101,7 @@ static int incomingFromDHT(struct DHTMessage* dmessage, void* vpf)
     Bits_memcpy(emsg->route.ip6, addr->ip6.bytes, 16);
     emsg->route.version_be = Endian_hostToBigEndian32(addr->protocolVersion);
     emsg->route.sh.label_be = Endian_hostToBigEndian64(addr->path);
+    emsg->route.flags |= RouteHeader_flags_PATHFINDER;
     SwitchHeader_setVersion(&emsg->route.sh, SwitchHeader_CURRENT_VERSION);
     Bits_memcpy(emsg->route.publicKey, addr->key, 32);
 

+ 14 - 6
net/SessionManager.c

@@ -106,7 +106,8 @@ struct SessionManager_Session_pvt
         AddrTools_printPath(sendPath, (session)->pub.sendSwitchLabel);                 \
         AddrTools_printPath(recvPath, (session)->pub.recvSwitchLabel);                 \
         AddrTools_printIp(ip, (session)->pub.caSession->herIp6);                       \
-        Log_debug((logger), "Session sendPath[%s] recvPath[%s] ip[%s] " message,       \
+        Log_debug((logger), "Session[%p] sendPath[%s] recvPath[%s] ip[%s] " message,   \
+                  session,                                                             \
                   sendPath,                                                            \
                   recvPath,                                                            \
                   ip,                                                                  \
@@ -204,12 +205,14 @@ static struct SessionManager_Session_pvt* getSession(struct SessionManager_pvt*
                                                      uint8_t pubKey[32],
                                                      uint32_t version,
                                                      uint64_t label,
-                                                     uint32_t metric)
+                                                     uint32_t metric,
+                                                     int maintainSession)
 {
     Assert_true(AddressCalc_validAddress(ip6));
     struct SessionManager_Session_pvt* sess = sessionForIp6(ip6, sm);
     if (sess) {
         sess->pub.version = (sess->pub.version) ? sess->pub.version : version;
+        sess->pub.maintainSession |= maintainSession;
         if (metric == 0xffffffff) {
             // this is a broken path
             if (sess->pub.sendSwitchLabel == label) {
@@ -263,6 +266,7 @@ static struct SessionManager_Session_pvt* getSession(struct SessionManager_pvt*
     sess->pub.timeOfLastOut = Time_currentTimeMilliseconds(sm->eventBase);
     sess->pub.sendSwitchLabel = label;
     sess->pub.metric = metric;
+    sess->pub.maintainSession = maintainSession;
     //Allocator_onFree(alloc, sessionCleanup, sess);
     sendSession(sess, label, 0xffffffff, PFChan_Core_SESSION);
     check(sm, ifaceIndex);
@@ -375,7 +379,7 @@ static Iface_DEFUN incomingFromSwitchIf(struct Message* msg, struct Iface* iface
         }
 
         uint64_t label = Endian_bigEndianToHost64(switchHeader->label_be);
-        session = getSession(sm, ip6, caHeader->publicKey, 0, label, 0xfffff000);
+        session = getSession(sm, ip6, caHeader->publicKey, 0, label, 0xfffff000, 0);
         CryptoAuth_resetIfTimeout(session->pub.caSession);
         debugHandlesAndLabel(sm->log, session, label, "new session nonce[%d]", nonceOrHandle);
     }
@@ -514,7 +518,9 @@ static void checkTimedOutSessions(struct SessionManager_pvt* sm)
             continue;
         }
 
-        if (now - sess->pub.lastSearchTime >= sm->pub.sessionSearchAfterMilliseconds) {
+        if (!sess->pub.maintainSession) {
+            // Let pathfinder maintain it's own sessions itself
+        } else if (now - sess->pub.lastSearchTime >= sm->pub.sessionSearchAfterMilliseconds) {
             // Session is not in idle state and requires a search
             // But we're only going to trigger one search per cycle.
             // Except for v20 because the snode will answer us.
@@ -678,7 +684,8 @@ static Iface_DEFUN incomingFromInsideIf(struct Message* msg, struct Iface* iface
                               header->publicKey,
                               Endian_bigEndianToHost32(header->version_be),
                               Endian_bigEndianToHost64(header->sh.label_be),
-                              0xfffffff0);
+                              0xfffffff0,
+                              !(header->flags & RouteHeader_flags_PATHFINDER));
         } else {
             needsLookup(sm, msg, false);
             return NULL;
@@ -753,7 +760,8 @@ static Iface_DEFUN incomingFromEventIf(struct Message* msg, struct Iface* iface)
                       node.publicKey,
                       Endian_bigEndianToHost32(node.version_be),
                       Endian_bigEndianToHost64(node.path_be),
-                      Endian_bigEndianToHost32(node.metric_be));
+                      Endian_bigEndianToHost32(node.metric_be),
+                      0);
 
     // Send what's on the buffer...
     if (index > -1 && CryptoAuth_getState(sess->pub.caSession) >= CryptoAuth_State_RECEIVED_KEY) {

+ 3 - 0
net/SessionManager.h

@@ -108,6 +108,9 @@ struct SessionManager_Session
 
     /** The switch label which this node uses for reaching us. */
     uint64_t recvSwitchLabel;
+
+    /** If non-zero, the peer will be periodically queries to maintain the session. */
+    int maintainSession;
 };
 
 struct SessionManager_HandleList

+ 1 - 0
net/SessionManager_admin.c

@@ -99,6 +99,7 @@ static void outputSession(struct Context* context,
     Dict_putIntC(r, "timeOfLastOut", session->timeOfLastOut, alloc);
 
     Dict_putIntC(r, "metric", session->metric, alloc);
+    Dict_putIntC(r, "maintainSession", session->maintainSession, alloc);
 
     Admin_sendMessage(r, txid, context->admin);
     return;

+ 3 - 2
wire/RouteHeader.h

@@ -52,8 +52,9 @@ struct RouteHeader
      * If set, this header is incoming from another node, this means the ip6, publicKey and
      * switch label are of the *source* of the packet, not the destination.
      */
-    #define RouteHeader_flags_INCOMING 1
-    #define RouteHeader_flags_CTRLMSG (1<<1)
+    #define RouteHeader_flags_INCOMING    1
+    #define RouteHeader_flags_CTRLMSG    (1<<1)
+    #define RouteHeader_flags_PATHFINDER (1<<2)
     uint8_t flags;
 
     uint8_t unused;