From eaffd192a80cf73caf793d0da749709b03405b84 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Sat, 18 Jul 2009 16:22:40 +0100 Subject: [PATCH] lan plugin config option for transmitting duplicate packets --- resolvers/lan/README.txt | 9 +++++++-- resolvers/lan/lan.cpp | 25 ++++++++++++++++--------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/resolvers/lan/README.txt b/resolvers/lan/README.txt index 1f9d85c..0177a4e 100644 --- a/resolvers/lan/README.txt +++ b/resolvers/lan/README.txt @@ -2,13 +2,15 @@ The LAN plugin broadcasts searches using UDP multicast. Results are streamed over HTTP using the address the UDP result came from. It should just automatically work on home/small office networks. -- -By default you don't need anything in the config file for this plugin, however: +By default you don't need anything in the config file for this plugin, however +the following options are valid if you need any of them: "lan" : { "listenip" : "your.lan.ip.address", "listenport" : 8888, - "endpoints" : ["239.255.0.1", "10.1.2.3", "192.168.1.1"] + "endpoints" : ["239.255.0.1", "10.1.2.3", "192.168.1.1"], + "numcopies" : 3 } * If you change the "listenport", it'll only work with others on the same port. @@ -23,3 +25,6 @@ By default you don't need anything in the config file for this plugin, however: machine you can reach on the LAN, despite multicast not working. * to change endpoint ports too: "endpoints" : [ ["10.1.2.3",1234], [..] ] + +* for lossy networks, set copies to more than 1, so your UDP packets stand a + better chance of being received. default is 1. diff --git a/resolvers/lan/lan.cpp b/resolvers/lan/lan.cpp index f973c86..936709d 100644 --- a/resolvers/lan/lan.cpp +++ b/resolvers/lan/lan.cpp @@ -219,15 +219,22 @@ lan::async_send(boost::asio::ip::udp::endpoint * remote_endpoint, //cout << "UDPsend[" << remote_endpoint.address() // << ":" << remote_endpoint.port() << "]" // << "(" << message << ")" << endl; - char * buf = (char*)malloc(message.length()); - memcpy(buf, message.data(), message.length()); - socket_->async_send_to( - boost::asio::buffer(buf,message.length()), - *remote_endpoint, - boost::bind(&lan::handle_send, this, - boost::asio::placeholders::error, - boost::asio::placeholders::bytes_transferred, - buf)); + + // you can set numcopies to 2 or 3 for lossy networks: + int copies = m_pap->get("plugins.lan.numcopies", 1); + if(copies<1) copies=1; + for(int j = 0; jasync_send_to( + boost::asio::buffer(buf,message.length()), + *remote_endpoint, + boost::bind(&lan::handle_send, this, + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred, + buf)); + } } void lan::handle_send( const boost::system::error_code& error,