Skip to content

Commit

Permalink
Don't busy-poll the snode to get routes to everything discovered by t…
Browse files Browse the repository at this point in the history
…he old pathfinder
  • Loading branch information
cjdelisle committed Oct 16, 2018
1 parent 1744356 commit 5edf834
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions dht/Pathfinder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
20 changes: 14 additions & 6 deletions net/SessionManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions net/SessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions net/SessionManager_admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions wire/RouteHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5edf834

Please sign in to comment.