From fcd1fa6e06e0fdc59d5d1c8941fb25647a10cd7a Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Sat, 8 Jun 2024 16:36:15 +0000 Subject: [PATCH] Parse RECEIVED and FAILED HsDescEvents --- .../tor/controller/HsDescEventParser.java | 31 ++++++++++++++++--- ...java => HsDescCreatedOrReceivedEvent.java} | 2 +- .../controller/events/events/HsDescEvent.java | 2 ++ .../events/events/HsDescFailedEvent.java | 12 +++++++ .../events/events/HsDescUploadEvent.java | 2 +- 5 files changed, 42 insertions(+), 7 deletions(-) rename network/tor/tor/src/main/java/bisq/tor/controller/events/events/{HsDescCreatedEvent.java => HsDescCreatedOrReceivedEvent.java} (77%) create mode 100644 network/tor/tor/src/main/java/bisq/tor/controller/events/events/HsDescFailedEvent.java diff --git a/network/tor/tor/src/main/java/bisq/tor/controller/HsDescEventParser.java b/network/tor/tor/src/main/java/bisq/tor/controller/HsDescEventParser.java index d38637ccca..4f962bf96b 100644 --- a/network/tor/tor/src/main/java/bisq/tor/controller/HsDescEventParser.java +++ b/network/tor/tor/src/main/java/bisq/tor/controller/HsDescEventParser.java @@ -1,9 +1,6 @@ package bisq.tor.controller; -import bisq.tor.controller.events.events.HsDescCreatedEvent; -import bisq.tor.controller.events.events.HsDescEvent; -import bisq.tor.controller.events.events.HsDescUploadEvent; -import bisq.tor.controller.events.events.HsDescUploadedEventV2; +import bisq.tor.controller.events.events.*; import java.util.Optional; @@ -11,7 +8,7 @@ public class HsDescEventParser { public static Optional tryParse(String[] parts) { if (HsDescEvent.Action.CREATED.isAction(parts)) { // 650 HS_DESC CREATED UNKNOWN UNKNOWN - HsDescCreatedEvent hsDescEvent = HsDescCreatedEvent.builder() + HsDescCreatedOrReceivedEvent hsDescEvent = HsDescCreatedOrReceivedEvent.builder() .action(HsDescEvent.Action.CREATED) .hsAddress(parts[3]) .authType(parts[4]) @@ -41,6 +38,30 @@ public static Optional tryParse(String[] parts) { .hsDir(parts[5]) .build(); return Optional.of(hsDescEvent); + + } else if (HsDescEvent.Action.RECEIVED.isAction(parts)) { + // 650 HS_DESC RECEIVED + HsDescCreatedOrReceivedEvent hsDescEvent = HsDescCreatedOrReceivedEvent.builder() + .action(HsDescEvent.Action.RECEIVED) + .hsAddress(parts[3]) + .authType(parts[4]) + .hsDir(parts[5]) + .descriptorId(parts[6]) + .build(); + return Optional.of(hsDescEvent); + + } else if (HsDescEvent.Action.FAILED.isAction(parts)) { + // 650 HS_DESC FAILED REASON=NOT_FOUND + HsDescCreatedOrReceivedEvent hsDescEvent = HsDescFailedEvent.builder() + .action(HsDescEvent.Action.FAILED) + .hsAddress(parts[3]) + .authType(parts[4]) + .hsDir(parts[5]) + .descriptorId(parts[6]) + .reason(parts[7]) + .build(); + return Optional.of(hsDescEvent); + } else { return Optional.empty(); } diff --git a/network/tor/tor/src/main/java/bisq/tor/controller/events/events/HsDescCreatedEvent.java b/network/tor/tor/src/main/java/bisq/tor/controller/events/events/HsDescCreatedOrReceivedEvent.java similarity index 77% rename from network/tor/tor/src/main/java/bisq/tor/controller/events/events/HsDescCreatedEvent.java rename to network/tor/tor/src/main/java/bisq/tor/controller/events/events/HsDescCreatedOrReceivedEvent.java index ca1d31c63c..ceea44f8bc 100644 --- a/network/tor/tor/src/main/java/bisq/tor/controller/events/events/HsDescCreatedEvent.java +++ b/network/tor/tor/src/main/java/bisq/tor/controller/events/events/HsDescCreatedOrReceivedEvent.java @@ -8,6 +8,6 @@ @SuperBuilder @Getter @ToString(callSuper = true) -public class HsDescCreatedEvent extends HsDescEvent { +public class HsDescCreatedOrReceivedEvent extends HsDescEvent { private final String descriptorId; } diff --git a/network/tor/tor/src/main/java/bisq/tor/controller/events/events/HsDescEvent.java b/network/tor/tor/src/main/java/bisq/tor/controller/events/events/HsDescEvent.java index 68ab216faf..091f627beb 100644 --- a/network/tor/tor/src/main/java/bisq/tor/controller/events/events/HsDescEvent.java +++ b/network/tor/tor/src/main/java/bisq/tor/controller/events/events/HsDescEvent.java @@ -12,6 +12,8 @@ public abstract class HsDescEvent { @Getter public enum Action { CREATED(7), + FAILED(8), + RECEIVED(7), UPLOAD(8), UPLOADED(6); diff --git a/network/tor/tor/src/main/java/bisq/tor/controller/events/events/HsDescFailedEvent.java b/network/tor/tor/src/main/java/bisq/tor/controller/events/events/HsDescFailedEvent.java new file mode 100644 index 0000000000..83dbd1d0ce --- /dev/null +++ b/network/tor/tor/src/main/java/bisq/tor/controller/events/events/HsDescFailedEvent.java @@ -0,0 +1,12 @@ +package bisq.tor.controller.events.events; + +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.SuperBuilder; + +@SuperBuilder +@Getter +@ToString(callSuper = true) +public class HsDescFailedEvent extends HsDescCreatedOrReceivedEvent { + private final String reason; +} diff --git a/network/tor/tor/src/main/java/bisq/tor/controller/events/events/HsDescUploadEvent.java b/network/tor/tor/src/main/java/bisq/tor/controller/events/events/HsDescUploadEvent.java index 4b3ff8abba..7affdc67ae 100644 --- a/network/tor/tor/src/main/java/bisq/tor/controller/events/events/HsDescUploadEvent.java +++ b/network/tor/tor/src/main/java/bisq/tor/controller/events/events/HsDescUploadEvent.java @@ -7,6 +7,6 @@ @SuperBuilder @Getter @ToString(callSuper = true) -public class HsDescUploadEvent extends HsDescCreatedEvent { +public class HsDescUploadEvent extends HsDescCreatedOrReceivedEvent { private final String hsDirIndex; }