X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FErrorAction.java;h=b7e592dd9d630c6628a6ab1e19f50b900f906e1c;hb=1854b5cebef22ace9e9e4dd191f609818df9ce08;hp=dd4e5604af2f909a330e91e5ee1ecbf5120ecae0;hpb=9d146759e11191b55130be7a1b6988d3f289a168;p=ldk-java diff --git a/src/main/java/org/ldk/structs/ErrorAction.java b/src/main/java/org/ldk/structs/ErrorAction.java index dd4e5604..b7e592dd 100644 --- a/src/main/java/org/ldk/structs/ErrorAction.java +++ b/src/main/java/org/ldk/structs/ErrorAction.java @@ -4,6 +4,7 @@ import org.ldk.impl.bindings; import org.ldk.enums.*; import org.ldk.util.*; import java.util.Arrays; +import java.lang.ref.Reference; import javax.annotation.Nullable; @@ -29,12 +30,18 @@ public class ErrorAction extends CommonBase { if (raw_val.getClass() == bindings.LDKErrorAction.IgnoreAndLog.class) { return new IgnoreAndLog(ptr, (bindings.LDKErrorAction.IgnoreAndLog)raw_val); } + if (raw_val.getClass() == bindings.LDKErrorAction.IgnoreDuplicateGossip.class) { + return new IgnoreDuplicateGossip(ptr, (bindings.LDKErrorAction.IgnoreDuplicateGossip)raw_val); + } if (raw_val.getClass() == bindings.LDKErrorAction.SendErrorMessage.class) { return new SendErrorMessage(ptr, (bindings.LDKErrorAction.SendErrorMessage)raw_val); } assert false; return null; // Unreachable without extending the (internal) bindings interface } + /** + * The peer took some action which made us think they were useless. Disconnect them. + */ public final static class DisconnectPeer extends ErrorAction { /** * An error message which we should make an effort to send before we disconnect. @@ -45,16 +52,23 @@ public class ErrorAction extends CommonBase { private DisconnectPeer(long ptr, bindings.LDKErrorAction.DisconnectPeer obj) { super(null, ptr); long msg = obj.msg; - ErrorMessage msg_hu_conv = new ErrorMessage(null, msg); + ErrorMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new ErrorMessage(null, msg); } msg_hu_conv.ptrs_to.add(this); this.msg = msg_hu_conv; } } + /** + * The peer did something harmless that we weren't able to process, just log and ignore + */ public final static class IgnoreError extends ErrorAction { private IgnoreError(long ptr, bindings.LDKErrorAction.IgnoreError obj) { super(null, ptr); } } + /** + * The peer did something harmless that we weren't able to meaningfully process. + * If the error is logged, log it at the given level. + */ public final static class IgnoreAndLog extends ErrorAction { public final Level ignore_and_log; private IgnoreAndLog(long ptr, bindings.LDKErrorAction.IgnoreAndLog obj) { @@ -62,6 +76,19 @@ public class ErrorAction extends CommonBase { this.ignore_and_log = obj.ignore_and_log; } } + /** + * The peer provided us with a gossip message which we'd already seen. In most cases this + * should be ignored, but it may result in the message being forwarded if it is a duplicate of + * our own channel announcements. + */ + public final static class IgnoreDuplicateGossip extends ErrorAction { + private IgnoreDuplicateGossip(long ptr, bindings.LDKErrorAction.IgnoreDuplicateGossip obj) { + super(null, ptr); + } + } + /** + * The peer did something incorrect. Tell them. + */ public final static class SendErrorMessage extends ErrorAction { /** * The message to send. @@ -70,17 +97,24 @@ public class ErrorAction extends CommonBase { private SendErrorMessage(long ptr, bindings.LDKErrorAction.SendErrorMessage obj) { super(null, ptr); long msg = obj.msg; - ErrorMessage msg_hu_conv = new ErrorMessage(null, msg); + ErrorMessage msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new ErrorMessage(null, msg); } msg_hu_conv.ptrs_to.add(this); this.msg = msg_hu_conv; } } + long clone_ptr() { + long ret = bindings.ErrorAction_clone_ptr(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + /** * Creates a copy of the ErrorAction */ public ErrorAction clone() { long ret = bindings.ErrorAction_clone(this.ptr); - if (ret < 1024) { return null; } + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret); ret_hu_conv.ptrs_to.add(this); return ret_hu_conv; @@ -91,7 +125,8 @@ public class ErrorAction extends CommonBase { */ public static ErrorAction disconnect_peer(ErrorMessage msg) { long ret = bindings.ErrorAction_disconnect_peer(msg == null ? 0 : msg.ptr & ~1); - if (ret < 1024) { return null; } + Reference.reachabilityFence(msg); + if (ret >= 0 && ret <= 4096) { return null; } ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret); ret_hu_conv.ptrs_to.add(ret_hu_conv); return ret_hu_conv; @@ -102,7 +137,7 @@ public class ErrorAction extends CommonBase { */ public static ErrorAction ignore_error() { long ret = bindings.ErrorAction_ignore_error(); - if (ret < 1024) { return null; } + if (ret >= 0 && ret <= 4096) { return null; } ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret); ret_hu_conv.ptrs_to.add(ret_hu_conv); return ret_hu_conv; @@ -113,7 +148,19 @@ public class ErrorAction extends CommonBase { */ public static ErrorAction ignore_and_log(org.ldk.enums.Level a) { long ret = bindings.ErrorAction_ignore_and_log(a); - if (ret < 1024) { return null; } + Reference.reachabilityFence(a); + if (ret >= 0 && ret <= 4096) { return null; } + ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(ret_hu_conv); + return ret_hu_conv; + } + + /** + * Utility method to constructs a new IgnoreDuplicateGossip-variant ErrorAction + */ + public static ErrorAction ignore_duplicate_gossip() { + long ret = bindings.ErrorAction_ignore_duplicate_gossip(); + if (ret >= 0 && ret <= 4096) { return null; } ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret); ret_hu_conv.ptrs_to.add(ret_hu_conv); return ret_hu_conv; @@ -124,7 +171,8 @@ public class ErrorAction extends CommonBase { */ public static ErrorAction send_error_message(ErrorMessage msg) { long ret = bindings.ErrorAction_send_error_message(msg == null ? 0 : msg.ptr & ~1); - if (ret < 1024) { return null; } + Reference.reachabilityFence(msg); + if (ret >= 0 && ret <= 4096) { return null; } ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret); ret_hu_conv.ptrs_to.add(ret_hu_conv); return ret_hu_conv;