Skip to content

Commit

Permalink
Merge branch 'crashey' of git://github.com/pdxmeshnet/cjdns into crashey
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdelisle committed Jun 14, 2016
2 parents 4397a5a + acbb6a8 commit c7e8c33
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
38 changes: 36 additions & 2 deletions tunnel/IpTunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,31 @@ static struct IpTunnel_Connection* newConnection(bool isOutgoing, struct IpTunne
return conn;
}

static void deleteConnection(struct IpTunnel_Connection* conn, struct IpTunnel_pvt* context)
{
// Delete connection and shift the list elements following the removed connection

int i = (((char *)conn)-((char *)&context->pub.connectionList.connections[0]))
/ sizeof(struct IpTunnel_Connection);

// Sanity check
Assert_true(i >= 0 && i < (signed int)context->pub.connectionList.count);

for (; (unsigned int)i < context->pub.connectionList.count-1; ++i) {
Bits_memcpy(&context->pub.connectionList.connections[i],
&context->pub.connectionList.connections[i + 1],
sizeof(struct IpTunnel_Connection));
}

int last = context->pub.connectionList.count-1;
if (last > 0) {
Bits_memset(&context->pub.connectionList.connections[last], 0,
sizeof(struct IpTunnel_Connection));
}

context->pub.connectionList.count--;
}

static struct IpTunnel_Connection* connectionByPubKey(uint8_t pubKey[32],
struct IpTunnel_pvt* context)
{
Expand Down Expand Up @@ -275,9 +300,18 @@ int IpTunnel_connectTo(uint8_t publicKeyOfNodeToConnectTo[32], struct IpTunnel*
*/
int IpTunnel_removeConnection(int connectionNumber, struct IpTunnel* tunnel)
{
//struct IpTunnel_pvt* context = Identity_check((struct IpTunnel_pvt*)tunnel);
struct IpTunnel_pvt* context = Identity_check((struct IpTunnel_pvt*)tunnel);

return 0;
for (int i = 0; i < (int)tunnel->connectionList.count; ++i)
{
if (tunnel->connectionList.connections[i].number==connectionNumber)
{
deleteConnection(&tunnel->connectionList.connections[i], context);
return 0;
}
}

return IpTunnel_removeConnection_NOT_FOUND;
}

static bool isControlMessageInvalid(struct Message* message, struct IpTunnel_pvt* context)
Expand Down
2 changes: 1 addition & 1 deletion tunnel/IpTunnel.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct IpTunnel

/**
* The list of registered connections, do not modify manually.
* Will be reorganized from time to time so pointers are ephimeral.
* Will be reorganized from time to time so pointers are ephemeral.
*/
struct {
uint32_t count;
Expand Down
9 changes: 4 additions & 5 deletions tunnel/IpTunnel_admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,13 @@ static void removeConnection(Dict* args,
struct Allocator* requestAlloc)
{
struct Context* context = vcontext;
/*

int conn = (int) *(Dict_getInt(args, String_CONST("connection")));
char* error = "none";
if (IpTunnel_removeConnection_NOT_FOUND == IpTunnel_removeConnection(conn, context->ipTun)) {
error = "not found";
sendError("not_found", txid, context->admin);
}
*/
sendError("not implemented", txid, context->admin);

sendResponse(conn, txid, context->admin);
}

static void listConnections(Dict* args,
Expand Down

0 comments on commit c7e8c33

Please sign in to comment.