diff --git a/src/com/frostwire/jlibtorrent/Address.java b/src/com/frostwire/jlibtorrent/Address.java new file mode 100644 index 000000000..9e7091138 --- /dev/null +++ b/src/com/frostwire/jlibtorrent/Address.java @@ -0,0 +1,20 @@ +package com.frostwire.jlibtorrent; + +import com.frostwire.jlibtorrent.swig.address; + +/** + * @author gubatron + * @author aldenml + */ +public final class Address { + + private final address addr; + + public Address(address addr) { + this.addr = addr; + } + + public address getSwig() { + return addr; + } +} diff --git a/src/com/frostwire/jlibtorrent/TcpEndpoint.java b/src/com/frostwire/jlibtorrent/TcpEndpoint.java new file mode 100644 index 000000000..ee098a3a5 --- /dev/null +++ b/src/com/frostwire/jlibtorrent/TcpEndpoint.java @@ -0,0 +1,20 @@ +package com.frostwire.jlibtorrent; + +import com.frostwire.jlibtorrent.swig.tcp_endpoint; + +/** + * @author gubatron + * @author aldenml + */ +public final class TcpEndpoint { + + private final tcp_endpoint endp; + + public TcpEndpoint(tcp_endpoint endp) { + this.endp = endp; + } + + public tcp_endpoint getSwig() { + return endp; + } +} diff --git a/src/com/frostwire/jlibtorrent/alerts/AlertType.java b/src/com/frostwire/jlibtorrent/alerts/AlertType.java index 095e98608..4704a6158 100644 --- a/src/com/frostwire/jlibtorrent/alerts/AlertType.java +++ b/src/com/frostwire/jlibtorrent/alerts/AlertType.java @@ -31,6 +31,10 @@ public enum AlertType { READ_PIECE(read_piece_alert.alert_type), STATE_CHANGED(state_changed_alert.alert_type), DHT_REPLY(dht_reply_alert.alert_type), + DHT_BOOTSTRAP_ALERT(dht_bootstrap_alert.alert_type), + DHT_GET_PEERS(dht_get_peers_alert.alert_type), + EXTERNAL_IP(external_ip_alert.alert_type), + LISTEN_SUCCEEDED(listen_succeeded_alert.alert_type), UNKNOWN(-1); private AlertType(int swigValue) { diff --git a/src/com/frostwire/jlibtorrent/alerts/DhtGetPeersAlert.java b/src/com/frostwire/jlibtorrent/alerts/DhtGetPeersAlert.java new file mode 100644 index 000000000..adc1fe942 --- /dev/null +++ b/src/com/frostwire/jlibtorrent/alerts/DhtGetPeersAlert.java @@ -0,0 +1,17 @@ +package com.frostwire.jlibtorrent.alerts; + +import com.frostwire.jlibtorrent.swig.dht_get_peers_alert; + +/** + * This alert is generated when a DHT node sends a ``get_peers`` message to + * our DHT node. It belongs to the ``dht_notification`` category. + * + * @author gubatron + * @author aldenml + */ +public final class DhtGetPeersAlert extends AbstractAlert { + + public DhtGetPeersAlert(dht_get_peers_alert alert) { + super(alert); + } +} diff --git a/src/com/frostwire/jlibtorrent/alerts/ExternalIpAlert.java b/src/com/frostwire/jlibtorrent/alerts/ExternalIpAlert.java new file mode 100644 index 000000000..39c977b8a --- /dev/null +++ b/src/com/frostwire/jlibtorrent/alerts/ExternalIpAlert.java @@ -0,0 +1,29 @@ +package com.frostwire.jlibtorrent.alerts; + +import com.frostwire.jlibtorrent.Address; +import com.frostwire.jlibtorrent.swig.external_ip_alert; + +/** + * Whenever libtorrent learns about the machines external IP, this alert is + * generated. The external IP address can be acquired from the tracker (if it + * supports that) or from peers that supports the extension protocol. + * The address can be accessed through the ``external_address`` member. + * + * @author gubatron + * @author aldenml + */ +public final class ExternalIpAlert extends AbstractAlert { + + public ExternalIpAlert(external_ip_alert alert) { + super(alert); + } + + /** + * the IP address that is believed to be our external IP. + * + * @return + */ + public Address getExternalAddress() { + return new Address(alert.getExternal_address()); + } +} diff --git a/src/com/frostwire/jlibtorrent/alerts/ListenSucceededAlert.java b/src/com/frostwire/jlibtorrent/alerts/ListenSucceededAlert.java new file mode 100644 index 000000000..7e23cb507 --- /dev/null +++ b/src/com/frostwire/jlibtorrent/alerts/ListenSucceededAlert.java @@ -0,0 +1,67 @@ +package com.frostwire.jlibtorrent.alerts; + +import com.frostwire.jlibtorrent.TcpEndpoint; +import com.frostwire.jlibtorrent.swig.listen_succeeded_alert; + +/** + * This alert is posted when the listen port succeeds to be opened on a + * particular interface. ``endpoint`` is the endpoint that successfully + * was opened for listening. + * + * @author gubatron + * @author aldenml + */ +public final class ListenSucceededAlert extends AbstractAlert { + + public ListenSucceededAlert(listen_succeeded_alert alert) { + super(alert); + } + + /** + * the endpoint libtorrent ended up listening on. The address + * refers to the local interface and the port is the listen port. + * + * @return + */ + public TcpEndpoint getEndpoint() { + return new TcpEndpoint(alert.getEndpoint()); + } + + /** + * the type of listen socket this alert refers to. + * + * @return + */ + public SocketType getSockType() { + return SocketType.fromSwig(alert.getSock_type()); + } + + public enum SocketType { + + TCP(listen_succeeded_alert.socket_type_t.tcp), + + TCP_SSL(listen_succeeded_alert.socket_type_t.tcp_ssl), + + UDP(listen_succeeded_alert.socket_type_t.udp); + + private SocketType(listen_succeeded_alert.socket_type_t swigObj) { + this.swigObj = swigObj; + } + + private final listen_succeeded_alert.socket_type_t swigObj; + + public listen_succeeded_alert.socket_type_t getSwig() { + return swigObj; + } + + public static SocketType fromSwig(listen_succeeded_alert.socket_type_t swigObj) { + SocketType[] enumValues = SocketType.class.getEnumConstants(); + for (SocketType ev : enumValues) { + if (ev.getSwig() == swigObj) { + return ev; + } + } + throw new IllegalArgumentException("No enum " + SocketType.class + " with swig value " + swigObj); + } + } +}