nodechan

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

commit b6b8d0ac4562d5ff1235652945cc78df0e952d5f
parent 04c5cc01006418232df288874c5d8a61df3edcf4
Author: joshiemoore <jxm5210@g.rit.edu>
Date:   Thu,  8 Aug 2019 23:35:57 -0400

Add client propagation of received packets to peers

Diffstat:
Msrc/ChanPost.java | 2+-
Msrc/IncomingThread.java | 20++++++++++++++++++--
Msrc/Peer.java | 7+++++++
3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/src/ChanPost.java b/src/ChanPost.java @@ -65,7 +65,7 @@ public class ChanPost { * will limit the number of times they forward a single post, unless they * are specifically requested to by another client. */ - public void heard() { + public void received() { this.receiptCount++; } diff --git a/src/IncomingThread.java b/src/IncomingThread.java @@ -62,7 +62,7 @@ public class IncomingThread extends Thread { boolean havePeer = false; for (Peer p : peers) { - if (p.getAddress().getHostAddress().equals(incoming.getHostAddress())) { + if (p.equalsAddress(incoming)) { p.heard(); havePeer = true; break; @@ -76,7 +76,6 @@ public class IncomingThread extends Thread { switch(recv_data[2]) { case 'P': - // TODO: post propagation/forwarding // decode the post packet ChanPost post = ChanPost.decodeUDP(recv_data); @@ -87,6 +86,7 @@ public class IncomingThread extends Thread { for (ChanThread t : threads) { if (t.getTid().equals(post.getTid())) { haveOP = true; + post = t.getPost(0); break; } } @@ -117,6 +117,7 @@ public class IncomingThread extends Thread { for (int i = 0; i < existThread.getNumPosts(); i++) { if (existThread.getPost(i).getPid().equals(post.getPid())) { havePost = true; + post = existThread.getPost(i); break; } } @@ -130,6 +131,21 @@ public class IncomingThread extends Thread { } } + // forward this packet to all peers (except the peer we received the + // packet from) + // + // limit the number of times this client propagates a single post + // based on NodeChan.MAX_PROPS + if (post.getReceiptCount() < NodeChan.MAX_PROPS) { + for (Peer p : peers) { + if (!p.equalsAddress(post.getSender_addr())) { + new OutgoingThread(p.getAddress(), NodeChan.NC_PORT, recv_data); + } + } + } + + post.received(); + break; } } diff --git a/src/Peer.java b/src/Peer.java @@ -36,6 +36,13 @@ public class Peer { this.lastHeard = System.currentTimeMillis(); } + /** + * Return whether or not the address of this peer equals another address + */ + public boolean equalsAddress(InetAddress other) { + return this.addr.getHostAddress().equals(other.getHostAddress()); + } + /* * getters */