From 977b2736565d734958667207596ffb329af3e609 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Thu, 26 Jul 2018 08:29:05 +0100 Subject: [PATCH] implement rejection suggestions --- .../core/connection/ConnectionAcceptor.groovy | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy b/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy index f8db770c..26bc7080 100644 --- a/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy @@ -12,6 +12,7 @@ import com.muwire.core.hostcache.HostCache import com.muwire.core.trust.TrustLevel import com.muwire.core.trust.TrustService +import groovy.json.JsonOutput import groovy.util.logging.Log @Log @@ -143,7 +144,18 @@ class ConnectionAcceptor { } else { log.info("rejecting connection, leaf:$leaf") e.outputStream.write("REJECT".bytes) - // TODO: suggest peers + def hosts = hostCache.getHosts(10) + if (!hosts.isEmpty()) { + def json = [:] + json.tryHosts = hosts.collect { d -> d.toBase64() } + json = JsonOutput.toJson(json) + def os = new DataOutputStream(e.outputStream) + os.writeShort(json.bytes.length) + os.write(json.bytes) + } + e.outputStream.flush() + e.close() + eventBus.publish(new ConnectionEvent(endpoint: e, incoming: true, status: ConnectionAttemptStatus.REJECTED)) } }