small method changes

This commit is contained in:
Joseph Henry 2015-09-11 14:00:42 -04:00
parent cc4a2bb0c3
commit 5a5a513b18
4 changed files with 22 additions and 18 deletions

View File

@ -84,7 +84,7 @@ else
CFLAGS?=-O3 -fstack-protector
CFLAGS+=-Wall -fPIE -fvisibility=hidden -pthread $(INCLUDES) -DNDEBUG $(DEFS)
CXXFLAGS?=-O3 -fstack-protector
CXXFLAGS+=-Wall -fPIE -fvisibility=hidden -fno-rtti -pthread $(INCLUDES) -DNDEBUG $(DEFS)
CXXFLAGS+=-Wall -Wreorder -fPIE -fvisibility=hidden -fno-rtti -pthread $(INCLUDES) -DNDEBUG $(DEFS)
LDFLAGS=-ldl -pie -Wl,-z,relro,-z,now
STRIP=strip --strip-all
endif

View File

@ -31,7 +31,6 @@
#include <utility>
#include <dlfcn.h>
#include "NetconEthernetTap.hpp"
#include "../node/Utils.hpp"
@ -200,6 +199,14 @@ void NetconEthernetTap::closeClient(NetconClient *client)
client->closeClient();
}
void NetconEthernetTap::closeConnection(NetconConnection *conn)
{
NetconClient *client = conn->owner;
_phy.close(conn->sock);
lwipstack->tcp_close(conn->pcb);
client->removeConnection(conn->sock);
}
void NetconEthernetTap::threadMain()
throw()
@ -239,9 +246,8 @@ void NetconEthernetTap::threadMain()
prev_etharp_time = curr_time;
lwipstack->etharp_tmr();
}
_phy.poll(min_time * 1000); // conversion from usec to millisec, TODO: double check
_phy.poll(min_time / 1000); // conversion from usec to millisec, TODO: double check
}
// TODO: cleanup -- destroy LWIP state, kill any clients, unload .so, etc.
}
@ -249,7 +255,7 @@ void NetconEthernetTap::threadMain()
void NetconEthernetTap::phyOnSocketPairEndpointClose(PhySocket *sock, void **uptr)
{
NetconClient *client = (NetconClient*)*uptr;
client->closeConnection(sock);
closeConnection(client->getConnection(sock));
}
void NetconEthernetTap::phyOnSocketPairEndpointData(PhySocket *sock, void **uptr, void *buf, unsigned long n)
@ -268,7 +274,7 @@ void NetconEthernetTap::phyOnSocketPairEndpointData(PhySocket *sock, void **uptr
void NetconEthernetTap::phyOnSocketPairEndpointWritable(PhySocket *sock, void **uptr)
{
//_phy.setNotifyWritable(sock, false);
}
// Unused -- no UDP or TCP from this thread/Phy<>
@ -395,7 +401,7 @@ err_t NetconEthernetTap::nc_recved(void *arg, struct tcp_pcb *tpcb, struct pbuf
if(c) {
nc_close(tpcb);
close(our_fd); // TODO: Check logic
c->owner->closeConnection(c);
tap->closeConnection(c);
}
else {
// can't locate connection via (arg)
@ -409,6 +415,7 @@ err_t NetconEthernetTap::nc_recved(void *arg, struct tcp_pcb *tpcb, struct pbuf
if((n = write(our_fd, p->payload, p->len)) > 0) {
if(n < p->len) {
// ERROR: unable to write entire pbuf to buffer
//tap->_phy.setNotifyWritable(l->sock, true);
}
tap->lwipstack->tcp_recved(tpcb, n);
}
@ -427,7 +434,7 @@ void NetconEthernetTap::nc_err(void *arg, err_t err)
NetconEthernetTap *tap = l->tap;
NetconConnection *c = tap->getConnectionByThisFD(tap->_phy.getDescriptor(l->sock));
if(c) {
c->owner->closeConnection(c);
l->tap->closeConnection(c);
//tcp_close(c->pcb);
}
else {

View File

@ -84,6 +84,8 @@ public:
void threadMain()
throw();
LWIPStack *lwipstack;
private:
// LWIP callbacks
@ -141,11 +143,11 @@ private:
NetconConnection *getConnectionByPCB(struct tcp_pcb *pcb);
NetconClient *getClientByPCB(struct tcp_pcb *pcb);
void closeClient(NetconClient *client);
void closeConnection(NetconConnection *conn);
Phy<NetconEthernetTap *> _phy;
PhySocket *_unixListenSocket;
LWIPStack *lwipstack;
std::vector<NetconClient*> clients;
uint64_t _nwid;

View File

@ -129,16 +129,11 @@ namespace ZeroTier {
return NULL;
}
void closeConnection(NetconConnection *c)
void removeConnection(PhySocket *sock)
{
// close all connections
// -- pcb
// -- PhySocket
}
void closeConnection(PhySocket *sock)
{
for(size_t i=0; i<connections.size(); i++) {
if(connections[i]->sock == sock) { connections.erase(connections.begin() + i); }
}
}
void closeClient()