From 3e02161b7d7bd175548e30991acfeefce0e758b2 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Fri, 27 Jul 2018 07:43:59 +0100 Subject: [PATCH] add top-level sendPing method to connections --- .../com/muwire/core/connection/Connection.groovy | 7 +++++++ .../core/connection/UltrapeerConnection.groovy | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/connection/Connection.groovy b/core/src/main/groovy/com/muwire/core/connection/Connection.groovy index bb927b19..95e80fc1 100644 --- a/core/src/main/groovy/com/muwire/core/connection/Connection.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/Connection.groovy @@ -95,4 +95,11 @@ abstract class Connection implements Closeable { } protected abstract void write(def message); + + void sendPing() { + def ping = [:] + ping.type = "Ping" + ping.version = 1 + messages.put(ping) + } } diff --git a/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnection.groovy b/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnection.groovy index 9c696dc2..cc193a7a 100644 --- a/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnection.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnection.groovy @@ -27,8 +27,18 @@ class UltrapeerConnection extends Connection { @Override protected void write(Object message) { - // TODO Auto-generated method stub - + if (message instanceof Map) { + writeJsonMessage(message) + } else { + writeBinaryMessage(message) + } } + private void writeJsonMessage(def message) { + + } + + private void writeBinaryMessage(def message) { + + } }