From d1aa994f8e77b87b0bab9907e7431fbf41fbf98b Mon Sep 17 00:00:00 2001 From: subtly Date: Thu, 18 Dec 2014 20:25:36 +0100 Subject: [PATCH] stash --- libp2p/UDP.h | 2 ++ test/net.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/libp2p/UDP.h b/libp2p/UDP.h index ff94df2ac..74499da11 100644 --- a/libp2p/UDP.h +++ b/libp2p/UDP.h @@ -68,11 +68,13 @@ public: UDPSocket(ba::io_service& _io, Handler& _host, unsigned _port): m_host(_host), m_socket(_io, bi::udp::endpoint(bi::udp::v4(), _port)) {}; virtual ~UDPSocket() { disconnect(); } + /// Socket will begin listening for and delivering packets void connect() { bool no = false; if (!m_started.compare_exchange_strong(no, true)) return; + m_closed = false; doRead(); } diff --git a/test/net.cpp b/test/net.cpp index 0b3208302..1e8d20c54 100644 --- a/test/net.cpp +++ b/test/net.cpp @@ -28,6 +28,21 @@ using namespace dev::p2p; namespace ba = boost::asio; namespace bi = ba::ip; +class Kademlia: UDPSocketEvents +{ +public: + Kademlia(): Worker("test",0), m_io(), m_socket(new UDPSocket(m_io, *this, 30300)) {} + ~Kademlia() { m_io.stop(); stopWorking(); } + + void onDisconnected(UDPSocketFace*) {}; + void onReceived(UDPSocketFace*, bi::udp::endpoint const& _from, bytesConstRef _packet) { if (_packet.toString() == "AAAA") success = true; } + + ba::io_service m_io; + shared_ptr> m_socket; + + bool success = false; +}; + class TestA: UDPSocketEvents, public Worker { public: