nodechan

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

commit 5b1b91fe9a1c0a6d4cc25690f8dd79999d9b8032
parent 76d2dedc04925465bee04413e39888158a74f7e7
Author: joshiemoore <jxm5210@g.rit.edu>
Date:   Tue,  6 Aug 2019 00:44:00 -0400

Retrieve local node's IP at application start

Diffstat:
M.gitignore | 1+
Msrc/NodeChan.java | 50+++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore @@ -1 +1,2 @@ *.class +/html/* diff --git a/src/NodeChan.java b/src/NodeChan.java @@ -1,5 +1,53 @@ +import java.util.Scanner; + +import java.io.BufferedReader; +import java.io.InputStreamReader; + +import java.net.URL; +import java.net.InetAddress; + +/** + * + * NodeChan is a peer-to-peer distributed anonymous messageboard. + * For more information, see README.MD. + * + */ public class NodeChan { + /** The IP address of this NodeChan node. **/ + private static String this_ip; + + /** The IP address of the first peer to connect to. **/ + private static String first_peer_ip; + public static void main(String[] args) { - System.out.println("NodeChan"); + // get the local ip address + try { + URL whatis = new URL("http://bot.whatismyipaddress.com"); + + BufferedReader sc = new BufferedReader(new InputStreamReader( + whatis.openStream())); + + this_ip = sc.readLine().trim(); + } catch (Exception e) { + System.err.println("Failed to retrieve this node's IP, quitting."); + return; + } + + System.out.println("Enter peer IP to connect directly, or leave blank to" + + " connect via the peer tracker: "); + + Scanner scan = new Scanner(System.in); + String input = scan.nextLine(); + + if (input.equals("")) { + // the user has opted to retrieve a peer from the database + + } else if (input.equals("debug")) { + // special debug peer + first_peer_ip = "debug"; + } else { + // attempt to connect directly to the peer + first_peer_ip = input; + } } }