/* * Copyright (c) 2011 Tobias Markmann * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* * Copyright (c) 2016-2018 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once #include #include #include #include #include #include #include #include #include #include #include namespace Swift { class EventLoop; class NATTraversalGetPublicIPRequest; class NATTraversalForwardPortRequest; class NATTraversalRemovePortForwardingRequest; class PlatformNATTraversalRequest; class NATPMPInterface; class MiniUPnPInterface; class NATTraversalInterface; class SWIFTEN_API PlatformNATTraversalWorker : public NATTraverser { friend class PlatformNATTraversalRequest; public: PlatformNATTraversalWorker(EventLoop* eventLoop); virtual ~PlatformNATTraversalWorker(); std::shared_ptr createGetPublicIPRequest(); std::shared_ptr createForwardPortRequest(unsigned short localPort, unsigned short publicPort); std::shared_ptr createRemovePortForwardingRequest(unsigned short localPort, unsigned short publicPort); private: NATTraversalInterface* getNATTraversalInterface() const; void addRequestToQueue(std::shared_ptr); void start(); void stop(); EventLoop* getEventLoop() const { return eventLoop; } private: EventLoop* eventLoop; Atomic stopRequested; std::thread* thread; std::deque > queue; std::mutex queueMutex; std::condition_variable queueNonEmpty; NullNATTraversalInterface* nullNATTraversalInterface; mutable boost::logic::tribool natPMPSupported; mutable NATPMPInterface* natPMPInterface; mutable boost::logic::tribool miniUPnPSupported; mutable MiniUPnPInterface* miniUPnPInterface; }; }