Skip to content

Commit

Permalink
Added CryptoAuth session state and ipv6 address to sessionStats
Browse files Browse the repository at this point in the history
  • Loading branch information
Caleb James DeLisle committed Dec 25, 2013
1 parent eeb619f commit 428d3f6
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 15 deletions.
5 changes: 3 additions & 2 deletions contrib/python/sessionStats
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ while True:


for h in handles: for h in handles:
r = cjdns.SessionManager_sessionStats(h); r = cjdns.SessionManager_sessionStats(h);
print(PublicToIp6_convert(r['publicKey']) + ' ' + r['publicKey'] + print(r['ip6'] + ' ' + r['publicKey'] +
' v' + str(r['version']) + ' v' + str(r['version']) +
' dup ' + str(r['duplicates']) + ' dup ' + str(r['duplicates']) +
' los ' + str(r['lostPackets']) + ' los ' + str(r['lostPackets']) +
' oor ' + str(r['receivedOutOfRange'])); ' oor ' + str(r['receivedOutOfRange']) +
' ' + r['state'].replace('CryptoAuth_', '') + ' ' + str(h));
13 changes: 12 additions & 1 deletion crypto/CryptoAuth.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ uint8_t* CryptoAuth_getHerPublicKey(struct Interface* iface);
/** Reset the session's state to CryptoAuth_NEW, a new connection will be negotiated. */ /** Reset the session's state to CryptoAuth_NEW, a new connection will be negotiated. */
void CryptoAuth_reset(struct Interface* iface); void CryptoAuth_reset(struct Interface* iface);



/** New CryptoAuth session, has not sent or received anything. */ /** New CryptoAuth session, has not sent or received anything. */
#define CryptoAuth_NEW 0 #define CryptoAuth_NEW 0


Expand All @@ -175,6 +174,18 @@ void CryptoAuth_reset(struct Interface* iface);
/** The CryptoAuth session has successfully done a handshake and received at least one message. */ /** The CryptoAuth session has successfully done a handshake and received at least one message. */
#define CryptoAuth_ESTABLISHED 4 #define CryptoAuth_ESTABLISHED 4


static inline char* CryptoAuth_stateString(int state)
{
switch (state) {
case CryptoAuth_NEW: return "CryptoAuth_NEW";
case CryptoAuth_HANDSHAKE1: return "CryptoAuth_HANDSHAKE1";
case CryptoAuth_HANDSHAKE2: return "CryptoAuth_HANDSHAKE2";
case CryptoAuth_HANDSHAKE3: return "CryptoAuth_HANDSHAKE3";
case CryptoAuth_ESTABLISHED: return "CryptoAuth_ESTABLISHED";
default: return "INVALID";
}
}

/** /**
* Get the state of the CryptoAuth session. * Get the state of the CryptoAuth session.
* *
Expand Down
9 changes: 9 additions & 0 deletions interface/SessionManager.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ static void cleanup(void* vsm)


static void check(struct SessionManager* sm, int mapIndex) static void check(struct SessionManager* sm, int mapIndex)
{ {
Assert_always(sm->ifaceMap.keys[mapIndex].bytes[0] == 0xfc);
uint8_t* herPubKey = CryptoAuth_getHerPublicKey(&sm->ifaceMap.values[mapIndex].iface); uint8_t* herPubKey = CryptoAuth_getHerPublicKey(&sm->ifaceMap.values[mapIndex].iface);
if (!Bits_isZero(herPubKey, 32)) { if (!Bits_isZero(herPubKey, 32)) {
uint8_t ip6[16]; uint8_t ip6[16];
Expand Down Expand Up @@ -166,6 +167,14 @@ struct SessionManager_Session* SessionManager_sessionForHandle(uint32_t handle,
return &sm->ifaceMap.values[index]; return &sm->ifaceMap.values[index];
} }


uint8_t* SessionManager_getIp6(uint32_t handle, struct SessionManager* sm)
{
int index = Map_OfSessionsByIp6_indexForHandle(handle - sm->first, &sm->ifaceMap);
if (index < 0) { return NULL; }
check(sm, index);
return sm->ifaceMap.keys[index].bytes;
}

struct SessionManager_HandleList* SessionManager_getHandleList(struct SessionManager* sm, struct SessionManager_HandleList* SessionManager_getHandleList(struct SessionManager* sm,
struct Allocator* alloc) struct Allocator* alloc)
{ {
Expand Down
9 changes: 9 additions & 0 deletions interface/SessionManager.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ struct SessionManager_Session* SessionManager_getSession(uint8_t* lookupKey,
struct SessionManager_Session* SessionManager_sessionForHandle(uint32_t handle, struct SessionManager_Session* SessionManager_sessionForHandle(uint32_t handle,
struct SessionManager* sm); struct SessionManager* sm);


/**
* Get the IPv6 address for a session.
*
* @param handle the handle for the session
* @param sm the session manager
* @return a binary ipv6 address or NULL.
*/
uint8_t* SessionManager_getIp6(uint32_t handle, struct SessionManager* sm);

/** /**
* Get the list of all handles. * Get the list of all handles.
*/ */
Expand Down
30 changes: 18 additions & 12 deletions interface/SessionManager_admin.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -59,22 +59,36 @@ static void getHandles(Dict* args, void* vcontext, String* txid, struct Allocato
Allocator_free(alloc); Allocator_free(alloc);
} }


static void sessionStats2(Dict* args, static void sessionStats(Dict* args,
struct Context* context, void* vcontext,
struct Allocator* alloc, String* txid,
String* txid) struct Allocator* alloc)
{ {
struct Context* context = vcontext;
int64_t* handleP = Dict_getInt(args, String_CONST("handle")); int64_t* handleP = Dict_getInt(args, String_CONST("handle"));
uint32_t handle = *handleP; uint32_t handle = *handleP;


struct SessionManager_Session* session = SessionManager_sessionForHandle(handle, context->sm); struct SessionManager_Session* session = SessionManager_sessionForHandle(handle, context->sm);
uint8_t* ip6 = SessionManager_getIp6(handle, context->sm);


Dict* r = Dict_new(alloc); Dict* r = Dict_new(alloc);
if (!session) { if (!session) {
Dict_putString(r, String_CONST("error"), String_CONST("no such session"), alloc); Dict_putString(r, String_CONST("error"), String_CONST("no such session"), alloc);
Admin_sendMessage(r, txid, context->admin); Admin_sendMessage(r, txid, context->admin);
return; return;
} }
// both or neither
Assert_always(ip6);

uint8_t printedAddr[40];
AddrTools_printIp(printedAddr, ip6);
Dict_putString(r, String_CONST("ip6"), String_new(printedAddr, alloc), alloc);

int state = CryptoAuth_getState(&session->iface);
Dict_putString(r,
String_CONST("state"),
String_new(CryptoAuth_stateString(state), alloc),
alloc);


struct ReplayProtector* rp = CryptoAuth_getReplayProtector(&session->iface); struct ReplayProtector* rp = CryptoAuth_getReplayProtector(&session->iface);
Dict_putInt(r, String_CONST("duplicates"), rp->duplicates, alloc); Dict_putInt(r, String_CONST("duplicates"), rp->duplicates, alloc);
Expand All @@ -93,14 +107,6 @@ static void sessionStats2(Dict* args,
return; return;
} }


static void sessionStats(Dict* args, void* vcontext, String* txid, struct Allocator* requestAlloc)
{
struct Context* context = vcontext;
struct Allocator* alloc = Allocator_child(context->alloc);
sessionStats2(args, context, alloc, txid);
Allocator_free(alloc);
}

void SessionManager_admin_register(struct SessionManager* sm, void SessionManager_admin_register(struct SessionManager* sm,
struct Admin* admin, struct Admin* admin,
struct Allocator* alloc) struct Allocator* alloc)
Expand Down

0 comments on commit 428d3f6

Please sign in to comment.