From fd061f615a18f047a01f3ea982d204a6867701a9 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Sat, 21 Jul 2018 21:49:02 +0100 Subject: [PATCH] type hierarchy of connections --- .../muwire/core/connection/Connection.groovy | 30 +++++++++++++++++++ .../core/connection/LeafConnection.groovy | 21 +++++++++++++ .../core/connection/PeerConnection.groovy | 21 +++++++++++++ .../connection/UltrapeerConnection.groovy | 23 ++++++++++++++ 4 files changed, 95 insertions(+) create mode 100644 core/src/main/groovy/com/muwire/core/connection/Connection.groovy create mode 100644 core/src/main/groovy/com/muwire/core/connection/LeafConnection.groovy create mode 100644 core/src/main/groovy/com/muwire/core/connection/PeerConnection.groovy create mode 100644 core/src/main/groovy/com/muwire/core/connection/UltrapeerConnection.groovy diff --git a/core/src/main/groovy/com/muwire/core/connection/Connection.groovy b/core/src/main/groovy/com/muwire/core/connection/Connection.groovy new file mode 100644 index 00000000..b6002d0e --- /dev/null +++ b/core/src/main/groovy/com/muwire/core/connection/Connection.groovy @@ -0,0 +1,30 @@ +package com.muwire.core.connection + +import com.muwire.core.EventBus + +import net.i2p.data.Destination + +abstract class Connection { + + final EventBus eventBus + final InputStream inputStream + final OutputStream outputStream + final Destination remoteSide + final boolean incoming + + Connection(EventBus eventBus, InputStream inputStream, OutputStream outputStream, + Destination remoteSide, boolean incoming) { + this.eventBus = eventBus + this.inputStream = inputStream + this.outputStream = outputStream + this.remoteSide = remoteSide + this.incoming = incoming + } + + /** + * starts the connection threads + */ + void start() { + + } +} diff --git a/core/src/main/groovy/com/muwire/core/connection/LeafConnection.groovy b/core/src/main/groovy/com/muwire/core/connection/LeafConnection.groovy new file mode 100644 index 00000000..7c1cf8b7 --- /dev/null +++ b/core/src/main/groovy/com/muwire/core/connection/LeafConnection.groovy @@ -0,0 +1,21 @@ +package com.muwire.core.connection + +import java.io.InputStream +import java.io.OutputStream + +import com.muwire.core.EventBus + +import net.i2p.data.Destination + +/** + * Connection where the other side is a leaf. + * Such connections can only be incoming. + * @author zab + */ +class LeafConnection extends Connection { + + public LeafConnection(EventBus eventBus, InputStream inputStream, OutputStream outputStream, Destination remoteSide) { + super(eventBus, inputStream, outputStream, remoteSide, true); + } + +} diff --git a/core/src/main/groovy/com/muwire/core/connection/PeerConnection.groovy b/core/src/main/groovy/com/muwire/core/connection/PeerConnection.groovy new file mode 100644 index 00000000..42a79bbd --- /dev/null +++ b/core/src/main/groovy/com/muwire/core/connection/PeerConnection.groovy @@ -0,0 +1,21 @@ +package com.muwire.core.connection + +import java.io.InputStream +import java.io.OutputStream + +import com.muwire.core.EventBus + +import net.i2p.data.Destination + +/** + * This side is an ultrapeer and the remote is an ultrapeer too + * @author zab + */ +class PeerConnection extends Connection { + + public PeerConnection(EventBus eventBus, InputStream inputStream, OutputStream outputStream, Destination remoteSide, + boolean incoming) { + super(eventBus, inputStream, outputStream, remoteSide, incoming) + } + +} diff --git a/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnection.groovy b/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnection.groovy new file mode 100644 index 00000000..05c76bed --- /dev/null +++ b/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnection.groovy @@ -0,0 +1,23 @@ +package com.muwire.core.connection + +import java.io.InputStream +import java.io.OutputStream + +import com.muwire.core.EventBus + +import net.i2p.data.Destination + +/** + * Connection where this side is a leaf and the + * other side an ultrapeer. Such connections can only + * be outgoing + * @author zab + */ +class UltrapeerConnection extends Connection { + + public UltrapeerConnection(EventBus eventBus, InputStream inputStream, OutputStream outputStream, + Destination remoteSide) { + super(eventBus, inputStream, outputStream, remoteSide, false) + } + +}