nodechan

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

commit 517122fbf01d8034673ba68b0a4f0c5775a84396
parent 0757770620e21e0ca9f17d6563c9f2a165e36ca5
Author: joshiemoore <jxm5210@g.rit.edu>
Date:   Tue,  6 Aug 2019 15:20:01 -0400

Add Peer

Diffstat:
M.gitignore | 1-
Mbuild.sh | 2+-
Mrun.sh | 2+-
Msrc/NodeChan.java | 6+++++-
Asrc/Peer.java | 32++++++++++++++++++++++++++++++++
5 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,2 +1 @@ *.class -/html/* diff --git a/build.sh b/build.sh @@ -1 +1 @@ -sudo javac -cp lib/WaifUPnP.jar src/*.java +sudo javac -cp lib/WaifUPnP.jar src/*.java -d build diff --git a/run.sh b/run.sh @@ -1 +1 @@ -sudo java -cp src/:lib/WaifUPnP.jar NodeChan +sudo java -cp build/:lib/WaifUPnP.jar NodeChan diff --git a/src/NodeChan.java b/src/NodeChan.java @@ -19,7 +19,7 @@ import com.dosse.upnp.UPnP; */ public class NodeChan { /** The port the application will use to connect. **/ - public static final int PORT = 13370; + public static int PORT = 13370; /** The IP address of this NodeChan node. **/ private static String node_ip; @@ -28,6 +28,8 @@ public class NodeChan { private static String first_peer_ip; public static void main(String[] args) { + System.out.println("Welcome to NodeChan."); + // get the local ip address try { URL whatis = new URL("http://bot.whatismyipaddress.com"); @@ -43,6 +45,8 @@ public class NodeChan { System.out.println("Your Node IP is " + node_ip + "\n"); + System.out.println("Attempting to enable UPnP port mapping..."); + if (UPnP.isUPnPAvailable()) { if (!UPnP.isMappedUDP(PORT)) { if (UPnP.openPortUDP(PORT)) { diff --git a/src/Peer.java b/src/Peer.java @@ -0,0 +1,32 @@ +import java.net.InetAddress; + +public class Peer { + /** This peer's address information **/ + private InetAddress addr; + + /** The time this peer was last heard **/ + private long lastHeard; + + public Peer(String ip, long time) { + this.addr = InetAddress.getByName(ip); + this.time = System.currentTimeMillis(); + } + + /** + * We just heard from this peer, update their time + */ + public void heard() { + this.time = System.currentTimeMillis(); + } + + /* + * getters + */ + public InetAddress getAddress() { + return addr; + } + + public long getLastHeard() { + return this.lastHeard; + } +}