-
-
Notifications
You must be signed in to change notification settings - Fork 135
/
ListenFailedAlert.java
133 lines (113 loc) · 3.78 KB
/
ListenFailedAlert.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package com.frostwire.jlibtorrent.alerts;
import com.frostwire.jlibtorrent.ErrorCode;
import com.frostwire.jlibtorrent.swig.listen_failed_alert;
/**
* This alert is generated when none of the ports, given in the port range, to
* session can be opened for listening. The {@link #listenInterface()} member is the
* interface and port that failed, {@link #getError()} is the error code describing
* the failure.
* <p/>
* libtorrent may sometimes try to listen on port 0, if all other ports failed.
* Port 0 asks the operating system to pick a port that's free). If that fails
* you may see a {@link com.frostwire.jlibtorrent.alerts.ListenFailedAlert} with port 0 even if you didn't ask to
* listen on it.
*
* @author gubatron
* @author aldenml
*/
public final class ListenFailedAlert extends AbstractAlert<listen_failed_alert> {
public ListenFailedAlert(listen_failed_alert alert) {
super(alert);
}
/**
* The interface libtorrent attempted to listen on that failed.
*
* @return
*/
public String listenInterface() {
return alert.listen_interface();
}
/**
* The error the system returned.
*
* @return
*/
public ErrorCode getError() {
return new ErrorCode(alert.getError());
}
/**
* The specific low level operation that failed.
*
* @return
* @see com.frostwire.jlibtorrent.alerts.ListenFailedAlert.Operation
*/
public Operation getOperation() {
return Operation.fromSwig(alert.getOperation());
}
/**
* The port attempted to be opened for listening.
*
* @return
*/
public int port() {
return alert.getPort();
}
/**
* The type of listen socket this alert refers to.
*
* @return
* @see com.frostwire.jlibtorrent.alerts.ListenFailedAlert.SocketType
*/
public SocketType getSocketType() {
return SocketType.fromSwig(alert.getSock_type().swigValue());
}
public enum SocketType {
TCP(listen_failed_alert.socket_type_t.tcp.swigValue()),
TCP_SSL(listen_failed_alert.socket_type_t.tcp_ssl.swigValue()),
UDP(listen_failed_alert.socket_type_t.udp.swigValue()),
I2P(listen_failed_alert.socket_type_t.i2p.swigValue()),
SOCKS5(listen_failed_alert.socket_type_t.socks5.swigValue()),
UNKNOWN(-1);
SocketType(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
public int getSwig() {
return swigValue;
}
public static SocketType fromSwig(int swigValue) {
SocketType[] enumValues = SocketType.class.getEnumConstants();
for (SocketType ev : enumValues) {
if (ev.getSwig() == swigValue) {
return ev;
}
}
return UNKNOWN;
}
}
public enum Operation {
PARSE_ADDR(listen_failed_alert.op_t.parse_addr.swigValue()),
OPEN(listen_failed_alert.op_t.open.swigValue()),
BIND(listen_failed_alert.op_t.bind.swigValue()),
LISTEN(listen_failed_alert.op_t.listen.swigValue()),
GET_PEER_NAME(listen_failed_alert.op_t.get_peer_name.swigValue()),
ACCEPT(listen_failed_alert.op_t.accept.swigValue()),
UNKNOWN(-1);
Operation(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
public int getSwig() {
return swigValue;
}
public static Operation fromSwig(int swigValue) {
Operation[] enumValues = Operation.class.getEnumConstants();
for (Operation ev : enumValues) {
if (ev.getSwig() == swigValue) {
return ev;
}
}
return UNKNOWN;
}
}
}