diff --git a/build.gradle b/build.gradle index 29da434..7ff395a 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ repositories { } dependencies { - compile 'com.github.iotaledger:ict:20b7fbbaa7ec3b3629e5e5c1ba7478daa994d50a' + compile 'com.github.iotaledger:ict:33c4673748b829c32310ff26ee8912ea29a9636f' compile 'com.google.code.gson:gson:2.8.5' compile group: 'org.danilopianini', name: 'gson-extras', version: '0.2.1' compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.1' diff --git a/src/main/java/com/ictreport/ixi/ReportIxiGossipListener.java b/src/main/java/com/ictreport/ixi/ReportIxiGossipListener.java deleted file mode 100644 index cd09e34..0000000 --- a/src/main/java/com/ictreport/ixi/ReportIxiGossipListener.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.ictreport.ixi; - -import com.ictreport.ixi.exchange.payloads.Payload; -import com.ictreport.ixi.exchange.processors.PingPayloadProcessor; -import com.ictreport.ixi.utils.Constants; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.iota.ict.ixi.ReportIxi; -import org.iota.ict.network.gossip.GossipEvent; -import org.iota.ict.network.gossip.GossipFilter; -import org.iota.ict.network.gossip.GossipListener; - -public class ReportIxiGossipListener implements GossipListener { - - private static final Logger log = LogManager.getLogger("ReportIxiGossipListener"); - - private final GossipFilter filter = new GossipFilter(); - private final ReportIxi reportIxi; - private final PingPayloadProcessor pingPayloadProcessor = new PingPayloadProcessor(); - - public ReportIxiGossipListener(final ReportIxi reportIxi) { - this.reportIxi = reportIxi; - filter.watchTag(Constants.TAG); - } - - public void onGossipEvent(final GossipEvent event) { - if (!filter.passes(event.getTransaction())) return; - - if (!event.isOwnTransaction()) { - if (reportIxi != null) { - try { - final Payload payload = Payload.deserialize(event.getTransaction().decodedSignatureFragments()); - pingPayloadProcessor.process(reportIxi, payload); - } catch (final Exception e) { - // Invalid payload received, ignore it... - } - } - } - } -} diff --git a/src/main/java/com/ictreport/ixi/api/PingSender.java b/src/main/java/com/ictreport/ixi/api/PingSender.java deleted file mode 100644 index a00d448..0000000 --- a/src/main/java/com/ictreport/ixi/api/PingSender.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.ictreport.ixi.api; - -import com.ictreport.ixi.exchange.payloads.Payload; -import com.ictreport.ixi.exchange.payloads.PingPayload; -import com.ictreport.ixi.exchange.payloads.SubmittedPingPayload; -import com.ictreport.ixi.utils.Constants; -import com.ictreport.ixi.utils.RCSRestCaller; -import com.ictreport.ixi.utils.RandomStringGenerator; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.iota.ict.ixi.ReportIxi; -import org.iota.ict.model.transaction.TransactionBuilder; -import org.iota.ict.utils.RestartableThread; - -import java.util.concurrent.TimeUnit; - -public class PingSender extends RestartableThread { - - private static final Logger log = LogManager.getLogger("ReportIxi/PingSender"); - - private final ReportIxi reportIxi; - private final Object waiter = new Object(); - - public PingSender(final ReportIxi reportIxi) { - super(log); - this.reportIxi = reportIxi; - } - - @Override - public void run() { - final RandomStringGenerator randomStringGenerator = new RandomStringGenerator(); - - while (isRunning()) { - if (reportIxi.getReportIxiContext().getUuid() != null) { - final PingPayload pingPayload = new PingPayload(randomStringGenerator.nextString()); - final String json = Payload.serialize(pingPayload); - - // Broadcast to neighbors - final TransactionBuilder t = new TransactionBuilder(); - t.tag = Constants.TAG; - t.asciiMessage(json); - reportIxi.getIxi().submit(t.buildWhileUpdatingTimestamp()); - - log.debug(String.format( - "Broadcasted PingPayload to Ict network: %s", - Payload.serialize(pingPayload)) - ); - - // Send to RCS - final SubmittedPingPayload submittedPingPayload = - new SubmittedPingPayload(reportIxi.getReportIxiContext().getUuid(), pingPayload); - - final String response = RCSRestCaller.send("submittedPingPayload", submittedPingPayload, false); - - if (response != null) { - log.debug(String.format( - "Sent SubmittedPingPayload to RCS: %s", - Payload.serialize(submittedPingPayload)) - ); - } - } - - if (isRunning()) { - synchronized (waiter) { - try { - waiter.wait(TimeUnit.MINUTES.toMillis(5)); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - } - } - - @Override - public void onTerminate() { - synchronized (waiter) { - waiter.notify(); - } - } -} diff --git a/src/main/java/com/ictreport/ixi/exchange/payloads/Payload.java b/src/main/java/com/ictreport/ixi/exchange/payloads/Payload.java index 6ecbf6f..06f8c67 100644 --- a/src/main/java/com/ictreport/ixi/exchange/payloads/Payload.java +++ b/src/main/java/com/ictreport/ixi/exchange/payloads/Payload.java @@ -11,10 +11,7 @@ public class Payload { public static String serialize(final Payload payload) { final RuntimeTypeAdapterFactory runtimeTypeAdapterFactory = RuntimeTypeAdapterFactory .of(Payload.class, "type") - .registerSubtype(PingPayload.class, "PingPayload") .registerSubtype(StatusPayload.class, "StatusPayload") - .registerSubtype(ReceivedPingPayload.class, "ReceivedPingPayload") - .registerSubtype(SubmittedPingPayload.class, "SubmittedPingPayload") .registerSubtype(RequestUuidPayload.class, "RequestUuidPayload") .registerSubtype(NeighborPayload.class, "NeighborPayload"); @@ -26,10 +23,7 @@ public static String serialize(final Payload payload) { public static Payload deserialize(final String json) { final RuntimeTypeAdapterFactory runtimeTypeAdapterFactory = RuntimeTypeAdapterFactory .of(Payload.class, "type") - .registerSubtype(PingPayload.class, "PingPayload") .registerSubtype(StatusPayload.class, "StatusPayload") - .registerSubtype(ReceivedPingPayload.class, "ReceivedPingPayload") - .registerSubtype(SubmittedPingPayload.class, "SubmittedPingPayload") .registerSubtype(RequestUuidPayload.class, "RequestUuidPayload") .registerSubtype(NeighborPayload.class, "NeighborPayload"); diff --git a/src/main/java/com/ictreport/ixi/exchange/payloads/PingPayload.java b/src/main/java/com/ictreport/ixi/exchange/payloads/PingPayload.java deleted file mode 100644 index d038e90..0000000 --- a/src/main/java/com/ictreport/ixi/exchange/payloads/PingPayload.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.ictreport.ixi.exchange.payloads; - -public class PingPayload extends Payload { - - private final String message; - - public PingPayload(final String message) { - this.message = message; - } - - public String getMessage() { - return message; - } -} diff --git a/src/main/java/com/ictreport/ixi/exchange/payloads/ReceivedPingPayload.java b/src/main/java/com/ictreport/ixi/exchange/payloads/ReceivedPingPayload.java deleted file mode 100644 index 142886b..0000000 --- a/src/main/java/com/ictreport/ixi/exchange/payloads/ReceivedPingPayload.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.ictreport.ixi.exchange.payloads; - -public class ReceivedPingPayload extends Payload { - - private final String uuid; - private final PingPayload pingPayload; - - public ReceivedPingPayload(final String uuid, final PingPayload pingPayload) { - this.uuid = uuid; - this.pingPayload = pingPayload; - } - - public String getUuid() { - return uuid; - } - - public PingPayload getPingPayload() { - return pingPayload; - } -} diff --git a/src/main/java/com/ictreport/ixi/exchange/payloads/SubmittedPingPayload.java b/src/main/java/com/ictreport/ixi/exchange/payloads/SubmittedPingPayload.java deleted file mode 100644 index d08a73f..0000000 --- a/src/main/java/com/ictreport/ixi/exchange/payloads/SubmittedPingPayload.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.ictreport.ixi.exchange.payloads; - -public class SubmittedPingPayload extends Payload { - - private final String uuid; - private final PingPayload pingPayload; - - public SubmittedPingPayload(final String uuid, final PingPayload pingPayload) { - this.uuid = uuid; - this.pingPayload = pingPayload; - } - - public String getUuid() { - return uuid; - } - - public PingPayload getPingPayload() { - return pingPayload; - } -} diff --git a/src/main/java/com/ictreport/ixi/exchange/processors/IPayloadProcessor.java b/src/main/java/com/ictreport/ixi/exchange/processors/IPayloadProcessor.java deleted file mode 100644 index 8410f7d..0000000 --- a/src/main/java/com/ictreport/ixi/exchange/processors/IPayloadProcessor.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.ictreport.ixi.exchange.processors; - -import com.ictreport.ixi.exchange.payloads.Payload; -import org.iota.ict.ixi.ReportIxi; - -public interface IPayloadProcessor { - - boolean process(final ReportIxi reportIxi, final Payload payload); -} diff --git a/src/main/java/com/ictreport/ixi/exchange/processors/PingPayloadProcessor.java b/src/main/java/com/ictreport/ixi/exchange/processors/PingPayloadProcessor.java deleted file mode 100644 index 1bd1b10..0000000 --- a/src/main/java/com/ictreport/ixi/exchange/processors/PingPayloadProcessor.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.ictreport.ixi.exchange.processors; - -import com.ictreport.ixi.exchange.payloads.Payload; -import com.ictreport.ixi.exchange.payloads.PingPayload; -import com.ictreport.ixi.exchange.payloads.ReceivedPingPayload; -import com.ictreport.ixi.utils.RCSRestCaller; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.iota.ict.ixi.ReportIxi; - -public class PingPayloadProcessor implements IPayloadProcessor { - - private static final Logger log = LogManager.getLogger("ReportIxi/PingPayloadProcessor"); - - public boolean process(final ReportIxi reportIxi, final Payload payload) { - - if (!(payload instanceof PingPayload)) { - return false; - } - - final PingPayload pingPayload = (PingPayload)payload; - - final ReceivedPingPayload receivedPingPayload = - new ReceivedPingPayload(reportIxi.getReportIxiContext().getUuid(), pingPayload); - - if (reportIxi.getReportIxiContext().getUuid() != null) { - RCSRestCaller.send("receivedPingPayload", receivedPingPayload, false); - } - - return true; - } -} diff --git a/src/main/java/org/iota/ict/ixi/ReportIxi.java b/src/main/java/org/iota/ict/ixi/ReportIxi.java index c52abc7..1d8220e 100644 --- a/src/main/java/org/iota/ict/ixi/ReportIxi.java +++ b/src/main/java/org/iota/ict/ixi/ReportIxi.java @@ -1,21 +1,17 @@ package org.iota.ict.ixi; import com.ictreport.ixi.ReportIxiContext; -import com.ictreport.ixi.ReportIxiGossipListener; -import com.ictreport.ixi.api.PingSender; import com.ictreport.ixi.api.StatusSender; import com.ictreport.ixi.configuration.Migrator; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.iota.ict.ixi.context.IxiContext; -import org.iota.ict.network.gossip.GossipListener; public class ReportIxi extends IxiModule { private static final Logger log = LogManager.getLogger("ReportIxi"); private final ReportIxiContext context = new ReportIxiContext(); - private final GossipListener gossipListener = new ReportIxiGossipListener(this); public ReportIxi(Ixi ixi) { super(ixi); @@ -38,9 +34,6 @@ public void onStart() { log.info("Starting ReportIxi ..."); subWorkers.add(new StatusSender(this)); - subWorkers.add(new PingSender(this)); - - getIxi().addGossipListener(gossipListener); } @Override @@ -61,7 +54,6 @@ public void run() { @Override public void onTerminate() { - getIxi().removeGossipListener(gossipListener); log.info("Stopped ReportIxi."); } diff --git a/src/test/java/com/ictreport/ixi/exchange/PingPayloadTest.java b/src/test/java/com/ictreport/ixi/exchange/PingPayloadTest.java deleted file mode 100644 index 85d8be8..0000000 --- a/src/test/java/com/ictreport/ixi/exchange/PingPayloadTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.ictreport.ixi.exchange; - -import com.ictreport.ixi.exchange.payloads.Payload; -import com.ictreport.ixi.exchange.payloads.PingPayload; -import org.junit.Assert; -import org.junit.Test; - -public class PingPayloadTest { - - @Test - public void testPingPayload() { - final PingPayload pingPayload = new PingPayload("abc"); - final String json = Payload.serialize(pingPayload); - final Payload deserializedPayload = Payload.deserialize(json); - - if (deserializedPayload instanceof PingPayload) { - final PingPayload deserializedPingPayload = (PingPayload) deserializedPayload; - Assert.assertEquals(deserializedPingPayload.getMessage(), pingPayload.getMessage()); - } else { - Assert.fail("Deserialization of polymorphism object failed."); - } - } -} diff --git a/src/test/java/com/ictreport/ixi/exchange/ReceivedPingPayloadTest.java b/src/test/java/com/ictreport/ixi/exchange/ReceivedPingPayloadTest.java deleted file mode 100644 index 1b84b43..0000000 --- a/src/test/java/com/ictreport/ixi/exchange/ReceivedPingPayloadTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.ictreport.ixi.exchange; - -import com.ictreport.ixi.exchange.payloads.Payload; -import com.ictreport.ixi.exchange.payloads.PingPayload; -import com.ictreport.ixi.exchange.payloads.ReceivedPingPayload; -import org.junit.Assert; -import org.junit.Test; - -public class ReceivedPingPayloadTest { - - @Test - public void testReceivedPingPayload() { - final PingPayload pingPayload = new PingPayload("abc"); - final ReceivedPingPayload receivedPingPayload = new ReceivedPingPayload("abc", pingPayload); - final String json = Payload.serialize(receivedPingPayload); - final Payload deserializedPayload = Payload.deserialize(json); - - if (deserializedPayload instanceof ReceivedPingPayload) { - final ReceivedPingPayload deserializedReceivedPingPayload = (ReceivedPingPayload) deserializedPayload; - Assert.assertEquals(deserializedReceivedPingPayload.getUuid(), receivedPingPayload.getUuid()); - Assert.assertEquals(deserializedReceivedPingPayload.getPingPayload().getMessage(), pingPayload.getMessage()); - } else { - Assert.fail("Deserialization of polymorphism object failed."); - } - } -} diff --git a/src/test/java/com/ictreport/ixi/exchange/SubmittedPingPayloadTest.java b/src/test/java/com/ictreport/ixi/exchange/SubmittedPingPayloadTest.java deleted file mode 100644 index 3a8a70a..0000000 --- a/src/test/java/com/ictreport/ixi/exchange/SubmittedPingPayloadTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.ictreport.ixi.exchange; - -import com.ictreport.ixi.exchange.payloads.Payload; -import com.ictreport.ixi.exchange.payloads.PingPayload; -import com.ictreport.ixi.exchange.payloads.SubmittedPingPayload; -import org.junit.Assert; -import org.junit.Test; - -public class SubmittedPingPayloadTest { - - @Test - public void testPingPayload() { - final PingPayload pingPayload = new PingPayload("abc"); - final SubmittedPingPayload submittedPingPayload = new SubmittedPingPayload("abc", pingPayload); - final String json = Payload.serialize(submittedPingPayload); - final Payload deserializedPayload = Payload.deserialize(json); - - if (deserializedPayload instanceof SubmittedPingPayload) { - final SubmittedPingPayload deserializedSubmittedPingPayload = (SubmittedPingPayload) deserializedPayload; - Assert.assertEquals(deserializedSubmittedPingPayload.getUuid(), submittedPingPayload.getUuid()); - Assert.assertEquals(deserializedSubmittedPingPayload.getPingPayload().getMessage(), pingPayload.getMessage()); - } else { - Assert.fail("Deserialization of polymorphism object failed."); - } - } -}