Skip to content

Commit

Permalink
More alert types.
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenml committed Oct 1, 2014
1 parent a4fae2d commit 6aa667d
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 0 deletions.
20 changes: 20 additions & 0 deletions 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;
}
}
20 changes: 20 additions & 0 deletions 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;
}
}
4 changes: 4 additions & 0 deletions src/com/frostwire/jlibtorrent/alerts/AlertType.java
Expand Up @@ -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) {
Expand Down
17 changes: 17 additions & 0 deletions 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<dht_get_peers_alert> {

public DhtGetPeersAlert(dht_get_peers_alert alert) {
super(alert);
}
}
29 changes: 29 additions & 0 deletions 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<external_ip_alert> {

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());
}
}
67 changes: 67 additions & 0 deletions 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<listen_succeeded_alert> {

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);
}
}
}

0 comments on commit 6aa667d

Please sign in to comment.