summaryrefslogtreecommitdiff
path: root/node/Switch.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2018-08-09 11:31:37 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2018-08-09 11:31:37 -0700
commit553101e8b5a988003f594037dda82301b0967625 (patch)
tree8fccc387144b19810bc26d5395666ebace4adbb0 /node/Switch.cpp
parent3cd0ab1b3bacd5596d7fec989b2cd9cb413f4314 (diff)
parente01c0adff28602d48ad6f0d618bee072ec7843da (diff)
downloadinfinitytier-553101e8b5a988003f594037dda82301b0967625.tar.gz
infinitytier-553101e8b5a988003f594037dda82301b0967625.zip
merge dev
Diffstat (limited to 'node/Switch.cpp')
-rw-r--r--node/Switch.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/node/Switch.cpp b/node/Switch.cpp
index fddbd581..7b517864 100644
--- a/node/Switch.cpp
+++ b/node/Switch.cpp
@@ -121,6 +121,7 @@ void Switch::onRemotePacket(void *tPtr,const int64_t localSocket,const InetAddre
// seeing a Packet::Fragment?
RXQueueEntry *const rq = _findRXQueueEntry(fragmentPacketId);
+ Mutex::Lock rql(rq->lock);
if (rq->packetId != fragmentPacketId) {
// No packet found, so we received a fragment without its head.
@@ -203,6 +204,7 @@ void Switch::onRemotePacket(void *tPtr,const int64_t localSocket,const InetAddre
);
RXQueueEntry *const rq = _findRXQueueEntry(packetId);
+ Mutex::Lock rql(rq->lock);
if (rq->packetId != packetId) {
// If we have no other fragments yet, create an entry and save the head
@@ -237,6 +239,7 @@ void Switch::onRemotePacket(void *tPtr,const int64_t localSocket,const InetAddre
IncomingPacket packet(data,len,path,now);
if (!packet.tryDecode(RR,tPtr)) {
RXQueueEntry *const rq = _nextRXQueueEntry();
+ Mutex::Lock rql(rq->lock);
rq->timestamp = now;
rq->packetId = packet.packetId();
rq->frag0 = packet;
@@ -762,6 +765,9 @@ void Switch::send(void *tPtr,Packet &packet,bool encrypt)
if (!_trySend(tPtr,packet,encrypt)) {
{
Mutex::Lock _l(_txQueue_m);
+ if (_txQueue.size() >= ZT_TX_QUEUE_SIZE) {
+ _txQueue.pop_front();
+ }
_txQueue.push_back(TXQueueEntry(dest,RR->node->now(),packet,encrypt));
}
if (!RR->topology->getPeer(tPtr,dest))
@@ -801,6 +807,7 @@ void Switch::doAnythingWaitingForPeer(void *tPtr,const SharedPtr<Peer> &peer)
const int64_t now = RR->node->now();
for(unsigned int ptr=0;ptr<ZT_RX_QUEUE_SIZE;++ptr) {
RXQueueEntry *const rq = &(_rxQueue[ptr]);
+ Mutex::Lock rql(rq->lock);
if ((rq->timestamp)&&(rq->complete)) {
if ((rq->frag0.tryDecode(RR,tPtr))||((now - rq->timestamp) > ZT_RECEIVE_QUEUE_TIMEOUT))
rq->timestamp = 0;
@@ -852,6 +859,7 @@ unsigned long Switch::doTimerTasks(void *tPtr,int64_t now)
for(unsigned int ptr=0;ptr<ZT_RX_QUEUE_SIZE;++ptr) {
RXQueueEntry *const rq = &(_rxQueue[ptr]);
+ Mutex::Lock rql(rq->lock);
if ((rq->timestamp)&&(rq->complete)) {
if ((rq->frag0.tryDecode(RR,tPtr))||((now - rq->timestamp) > ZT_RECEIVE_QUEUE_TIMEOUT)) {
rq->timestamp = 0;