diff --git a/make.py b/make.py index ab076e0..49ef5dc 100755 --- a/make.py +++ b/make.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 #from __future__ import print_function import os diff --git a/src/core/peer_core.cc b/src/core/peer_core.cc index 8efe0e7..5d3bb3c 100644 --- a/src/core/peer_core.cc +++ b/src/core/peer_core.cc @@ -573,6 +573,28 @@ namespace p2psp { // }}} } + + + std::string Peer_core::RESTSplitter(std::string channel_url) { + boost::system::error_code ec; + io_service svc; + ip::tcp::socket rest(svc); + rest.connect({ {}, 3000 }); + std::string request("GET /channel/"+channel_url+" HTTP/1.1\r\n\r\n"); + rest.send(buffer(request)); + std::string data; + + do { + char buf[1024]; + size_t bytes_transferred = rest.receive(buffer(buf), {}, ec); + if (!ec) data.append(buf, buf + bytes_transferred); + } while (!ec); + + int split=data.find("\"splitterAddress\":\"")+19; + int next_split=data.find("\"",split); + data=data.substr(split,next_split-split); + return data; + } uint16_t Peer_core::GetSplitterPort() { // {{{ diff --git a/src/core/peer_core.h b/src/core/peer_core.h index 47636cc..4f6df83 100644 --- a/src/core/peer_core.h +++ b/src/core/peer_core.h @@ -85,6 +85,7 @@ namespace p2psp { virtual void Init(); + virtual std::string RESTSplitter(std::string channel_url); virtual void SetSplitterAddr(ip::address splitter_addr); virtual ip::address GetSplitterAddr(); static ip::address GetDefaultSplitterAddr();