nodechan

decentralized peer-to-peer anonymous messageboard client
git clone git://squid-tech.com/nodechan.git
Log | Files | Refs | README

commit 4b3ed17ece1e24b5e8cfb988737128d98c10e8ca
parent 5b1b91fe9a1c0a6d4cc25690f8dd79999d9b8032
Author: joshiemoore <jxm5210@g.rit.edu>
Date:   Tue,  6 Aug 2019 01:04:03 -0400

Retrieve peer from peer tracker server

Diffstat:
Msrc/NodeChan.java | 22++++++++++++++++++++++
1 file changed, 22 insertions(+), 0 deletions(-)

diff --git a/src/NodeChan.java b/src/NodeChan.java @@ -41,7 +41,9 @@ public class NodeChan { if (input.equals("")) { // the user has opted to retrieve a peer from the database + first_peer_ip = retrieve_peer(this_ip); + System.out.println(first_peer_ip); } else if (input.equals("debug")) { // special debug peer first_peer_ip = "debug"; @@ -50,4 +52,24 @@ public class NodeChan { first_peer_ip = input; } } + + /** + * Retrieve a peer from the peer database. + * + * @param me - the IP address of the local node + */ + public static String retrieve_peer(String me) { + try { + URL peer_db = new URL("http://nodechan.000webhostapp.com/nodes/naccess" + + ".php?ip=" + this_ip); + + BufferedReader sc = new BufferedReader(new InputStreamReader( + peer_db.openStream())); + + return sc.readLine().trim(); + } catch(Exception e) { + System.err.println("Failed to connect to peer tracker, quitting."); + return "ptfail"; + } + } }