From 945d4a67315f242627913671d3bc9e603e652044 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Mon, 9 Jul 2018 23:50:38 +0100 Subject: [PATCH] working pinger --- .../groovy/com/muwire/pinger/Pinger.groovy | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/pinger/src/main/groovy/com/muwire/pinger/Pinger.groovy b/pinger/src/main/groovy/com/muwire/pinger/Pinger.groovy index 42ebb813..b09cdfc2 100644 --- a/pinger/src/main/groovy/com/muwire/pinger/Pinger.groovy +++ b/pinger/src/main/groovy/com/muwire/pinger/Pinger.groovy @@ -1,7 +1,42 @@ package com.muwire.pinger + + +import java.nio.file.Files +import java.nio.file.Path + +import net.i2p.client.I2PClientFactory +import net.i2p.client.I2PSession +import net.i2p.client.datagram.I2PDatagramMaker +import net.i2p.data.Destination + public class Pinger { public static void main(String []args) { - println "ping" + if (args.length != 2) { + println "Pass b64 destination as argument 1 and file with contents to send as argument 2" + System.exit(1) + } + + def target = new Destination(args[0]) + def payload = (new File(args[1])).getBytes() + + def i2pClientFactory = new I2PClientFactory() + def i2pClient = i2pClientFactory.createClient() + + def props = System.getProperties().clone() + props.putAt("outbound.nickname", "MuWire Pinger") + + def baos = new ByteArrayOutputStream() + def myDest = i2pClient.createDestination(baos) + def bais = new ByteArrayInputStream(baos.toByteArray()) + + def session = i2pClient.createSession(bais, props) + + session.connect() + println "connected" + + def maker = new I2PDatagramMaker(session) + payload = maker.makeI2PDatagram(payload) + session.sendMessage(target, payload, I2PSession.PROTO_DATAGRAM, 0, 0) } }