Skip to content

Commit

Permalink
Report non-ESTABLISHED sessions to a rumormill so these nodes will be…
Browse files Browse the repository at this point in the history
… pinged
  • Loading branch information
cjdelisle committed Jan 29, 2015
1 parent adc3132 commit 507223d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion admin/angel/Core.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,8 @@ void Core_init(struct Allocator* alloc,
alloc,
logger,
ipTun,
rand);
rand,
rumorMill);

struct SwitchPinger* sp =
SwitchPinger_new(&dt->switchPingerIf, eventBase, rand, logger, &addr, alloc);
Expand Down
18 changes: 15 additions & 3 deletions net/Ducttape.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "util/Checksum.h"
#include "util/version/Version.h"
#include "util/Assert.h"
#include "util/events/Timeout.h"
#include "tunnel/IpTunnel.h"
#include "util/events/Time.h"
#include "util/Defined.h"
Expand Down Expand Up @@ -1239,13 +1240,20 @@ static uint8_t incomingFromPinger(struct Message* message, struct Interface* ifa
static void checkStateOfSessions(void* vducttape)
{
struct Ducttape_pvt* ctx = Identity_check((struct Ducttape_pvt*) vducttape);
if (!ctx->sessionMill) { return; }
struct Allocator* alloc = Allocator_child(ctx->alloc);
struct SessionManager_HandleList* handles = SessionManager_getHandleList(ctx->sm, alloc);
for (int i = 0; i < handles->count; i++) {
for (int i = 0; i < (int)handles->count; i++) {
struct SessionManager_Session* sess =
SessionManager_sessionForHandle(handles->handles[i], ctx->sm);
if (sess->cryptoAuthState == CryptoAuth_ESTABLISHED) { continue; }

if (!sess->knownSwitchLabel) { continue; }
uint8_t* hpk = CryptoAuth_getHerPublicKey(sess->internal);
if (Bits_isZero(hpk, 32)) { continue; }
struct Address addr = { .path = sess->knownSwitchLabel };
Bits_memcpyConst(addr.key, hpk, 32);
Address_getPrefix(&addr);
RumorMill_addNode(ctx->sessionMill, &addr);
}
}

Expand All @@ -1257,14 +1265,16 @@ struct Ducttape* Ducttape_register(uint8_t privateKey[32],
struct Allocator* allocator,
struct Log* logger,
struct IpTunnel* ipTun,
struct Random* rand)
struct Random* rand,
struct RumorMill* sessionMill)
{
struct Ducttape_pvt* context = Allocator_calloc(allocator, sizeof(struct Ducttape_pvt), 1);
context->registry = registry;
context->router = router;
context->logger = logger;
context->eventBase = eventBase;
context->alloc = allocator;
context->sessionMill = sessionMill;
Bits_memcpyConst(&context->pub.magicInterface, (&(struct Interface) {
.sendMessage = magicInterfaceSendMessage,
.allocator = allocator
Expand Down Expand Up @@ -1316,6 +1326,8 @@ struct Ducttape* Ducttape_register(uint8_t privateKey[32],
.senderContext = context
}), sizeof(struct Interface));

Timeout_setInterval(checkStateOfSessions, context, 10000, eventBase, allocator);

return &context->pub;
}

Expand Down
3 changes: 2 additions & 1 deletion net/Ducttape.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ struct Ducttape* Ducttape_register(uint8_t privateKey[32],
struct Allocator* allocator,
struct Log* logger,
struct IpTunnel* ipTun,
struct Random* rand);
struct Random* rand,
struct RumorMill* sessionMill);

/**
* Set the interface which the user will use to communicate with the network.
Expand Down
2 changes: 2 additions & 0 deletions net/Ducttape_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ struct Ducttape_pvt

struct EventBase* eventBase;

struct RumorMill* sessionMill;

struct Log* logger;

/** For tunneling IPv4 and ICANN IPv6 packets. */
Expand Down
2 changes: 1 addition & 1 deletion test/TestFramework.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ struct TestFramework* TestFramework_setUp(char* privateKey,

struct Ducttape* dt =
Ducttape_register((uint8_t*)privateKey, registry, router,
switchCore, base, allocator, logger, ipTun, rand);
switchCore, base, allocator, logger, ipTun, rand, rumorMill);

struct SwitchPinger* sp =
SwitchPinger_new(&dt->switchPingerIf, base, rand, logger, myAddress, allocator);
Expand Down

0 comments on commit 507223d

Please sign in to comment.