Skip to content

Commit

Permalink
Parse RECEIVED and FAILED HsDescEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
alvasw committed Jun 8, 2024
1 parent c597205 commit fcd1fa6
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
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;

public class HsDescEventParser {
public static Optional<HsDescEvent> tryParse(String[] parts) {
if (HsDescEvent.Action.CREATED.isAction(parts)) {
// 650 HS_DESC CREATED <onion_address> UNKNOWN UNKNOWN <descriptor_id>
HsDescCreatedEvent hsDescEvent = HsDescCreatedEvent.builder()
HsDescCreatedOrReceivedEvent hsDescEvent = HsDescCreatedOrReceivedEvent.builder()
.action(HsDescEvent.Action.CREATED)
.hsAddress(parts[3])
.authType(parts[4])
Expand Down Expand Up @@ -41,6 +38,30 @@ public static Optional<HsDescEvent> tryParse(String[] parts) {
.hsDir(parts[5])
.build();
return Optional.of(hsDescEvent);

} else if (HsDescEvent.Action.RECEIVED.isAction(parts)) {
// 650 HS_DESC RECEIVED <onion_address> <auth_type> <hs_dir> <descriptor_id>
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 <onion_address> <auth_type> <hs_dir> <descriptor_id> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
@SuperBuilder
@Getter
@ToString(callSuper = true)
public class HsDescCreatedEvent extends HsDescEvent {
public class HsDescCreatedOrReceivedEvent extends HsDescEvent {
private final String descriptorId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public abstract class HsDescEvent {
@Getter
public enum Action {
CREATED(7),
FAILED(8),
RECEIVED(7),
UPLOAD(8),
UPLOADED(6);

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
@SuperBuilder
@Getter
@ToString(callSuper = true)
public class HsDescUploadEvent extends HsDescCreatedEvent {
public class HsDescUploadEvent extends HsDescCreatedOrReceivedEvent {
private final String hsDirIndex;
}

0 comments on commit fcd1fa6

Please sign in to comment.