Package com.frostwire.jlibtorrent
Enum Class Operation
- All Implemented Interfaces:
Serializable,Comparable<Operation>,Constable
Identifies the type of operation that caused an error or peer disconnect.
Operation categorizes failures in libtorrent by the operation being performed
when the error occurred. Useful for diagnosing problems and implementing operation-specific
error handling. See PeerError for peer disconnects with error details.
Understanding Operation Failures:
// When a peer disconnects with an error
sm.addListener(new AlertListener() {
public int[] types() {
return new int[] {AlertType.PEER_DISCONNECTED.swig()};
}
public void alert(Alert<?> alert) {
PeerDisconnectedAlert a = (PeerDisconnectedAlert) alert;
PeerError error = a.error();
Operation op = error.operation();
ErrorCode ec = error.errorCode();
System.out.println(\"Peer failed during: \" + op);
System.out.println(\"Error: \" + ec.message());
// Handle based on operation type
if (op == Operation.SOCK_READ) {
System.out.println(\"Network read timeout or connection reset\");
} else if (op == Operation.FILE_WRITE) {
System.out.println(\"Disk write failed (space, permissions?)\");
}
}
});
Common Operations Causing Failures:
- Network I/O: SOCK_READ, SOCK_WRITE, CONNECT, SOCK_OPEN
- File I/O: FILE_READ, FILE_WRITE, FILE_OPEN, FILE_STAT
- Protocol: ENCRYPTION, BITTORRENT (protocol-level error)
- System: ALLOC_RECVBUF, ALLOC_SNDBUF (out of memory)
Network Operations:
SOCK_READ: Read from socket failed (timeout, connection reset, no data) SOCK_WRITE: Write to socket failed (connection broken, pipe full) SOCK_OPEN: Creating socket failed (resource limits) SOCK_BIND: Binding to port failed (port in use, permission denied) SOCK_LISTEN: Making socket listen failed SOCK_ACCEPT: Accepting connection failed SOCK_BIND_TO_DEVICE: Binding to specific network adapter failed CONNECT: Connection attempt failed (refused, timeout, unreachable) AVAILABLE: Querying available data failed
File Operations:
FILE_READ: Reading file failed (I/O error, file vanished) FILE_WRITE: Writing file failed (disk full, permission denied) FILE_OPEN: Opening file failed (not found, permission denied) FILE_STAT: Querying file info failed (file deleted, permission) FILE_COPY: Copying file failed FILE_REMOVE: Deleting file failed FILE_RENAME: Renaming file failed FILE_FALLOCATE: Pre-allocating space failed (disk full, unsupported) FILE_HARD_LINK: Creating hard link failed MKDIR: Creating directory failed
Protocol and Crypto Operations:
ENCRYPTION: BitTorrent protocol encryption failed (corrupt data) BITTORRENT: BitTorrent protocol logic error (invalid message) SSL_HANDSHAKE: TLS/SSL handshake failed (invalid certificate, version mismatch) PARSE_ADDRESS: Parsing IP address string failed (invalid format)
Memory and Resource Operations:
ALLOC_RECVBUF: Allocating receive buffer failed (out of memory) ALLOC_SNDBUF: Allocating send buffer failed (out of memory) ALLOC_CACHE_PIECE: Allocating piece cache failed (out of memory)
Diagnostic Uses:
// Track frequent failure types
java.util.Map<Operation, Integer> failures = new java.util.HashMap<>();
sm.addListener(new AlertListener() {
public int[] types() {
return new int[] {AlertType.PEER_DISCONNECTED.swig()};
}
public void alert(Alert<?> alert) {
PeerDisconnectedAlert a = (PeerDisconnectedAlert) alert;
Operation op = a.error().operation();
failures.put(op, failures.getOrDefault(op, 0) + 1);
}
});
// Later: analyze patterns
// Too many FILE_WRITE failures? → Disk problem
// Too many SOCK_READ? → Network instability
// Too many ALLOC_*? → Memory pressure
Using Operation.nativeName():
Operation op = Operation.FILE_WRITE; String name = op.nativeName(); // "file_write" (from C++ library) // For logging/debugging System.out.println(\"Failed operation: \" + name);
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionAn attempt to allocate a receive buffer failed.An attempt to allocate a send buffer failed.An attempt to query the number of bytes available to read from a socket failed.This is used when the bittorrent logic determines to disconnect.An attempt to connect a socket failed.A call related to bittorrent protocol encryption failed.Enumeration network devices or adapters.A non-read and non-write file operation failed.Reading from a file failed.Writing to a file failed.A connection failed to satisfy the bind interface setting.A call to getname failed (querying the local IP of a connection).A call to getpeername failed (querying the remote IP of a connection).A call to iocontrol failed.Convert a string into a valid network address.A call to accept() on a socket.A call to bind() on a socket failed.A call to the ioctl to bind a socket to a specific network device or adaptor.A call to listen() on a socket.A call to open(), to create a socket socket failed.A socket read operation failed.A socket write operation failed.Establishing an SSL connection failed.The error was unexpected and it is unknown which operation caused it. -
Method Summary
Modifier and TypeMethodDescriptionstatic OperationfromSwig(int swigValue) static OperationfromSwig(com.frostwire.jlibtorrent.swig.operation_t swigValue) intswig()static OperationReturns the enum constant of this class with the specified name.static Operation[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
UNKNOWN
The error was unexpected and it is unknown which operation caused it. -
BITTORRENT
This is used when the bittorrent logic determines to disconnect. -
IOCONTROL
A call to iocontrol failed. -
GETPEERNAME
A call to getpeername failed (querying the remote IP of a connection). -
GETNAME
A call to getname failed (querying the local IP of a connection). -
ALLOC_RECVBUF
An attempt to allocate a receive buffer failed. -
ALLOC_SNDBUF
An attempt to allocate a send buffer failed. -
FILE_WRITE
Writing to a file failed. -
FILE_READ
Reading from a file failed. -
FILE
A non-read and non-write file operation failed. -
SOCK_WRITE
A socket write operation failed. -
SOCK_READ
A socket read operation failed. -
SOCK_OPEN
A call to open(), to create a socket socket failed. -
SOCK_BIND
A call to bind() on a socket failed. -
AVAILABLE
An attempt to query the number of bytes available to read from a socket failed. -
ENCRYPTION
A call related to bittorrent protocol encryption failed. -
CONNECT
An attempt to connect a socket failed. -
SSL_HANDSHAKE
Establishing an SSL connection failed. -
GET_INTERFACE
A connection failed to satisfy the bind interface setting. -
SOCK_LISTEN
A call to listen() on a socket. -
SOCK_BIND_TO_DEVICE
A call to the ioctl to bind a socket to a specific network device or adaptor. -
SOCK_ACCEPT
A call to accept() on a socket. -
PARSE_ADDRESS
Convert a string into a valid network address. -
ENUM_IF
Enumeration network devices or adapters. -
FILE_STAT
-
FILE_COPY
-
FILE_FALLOCATE
-
FILE_HARD_LINK
-
FILE_REMOVE
-
FILE_RENAME
-
FILE_OPEN
-
MKDIR
-
CHECK_RESUME
-
EXCEPTION
-
ALLOC_CACHE_PIECE
-
PARTFILE_MOVE
-
PARTFILE_READ
-
PARTFILE_WRITE
-
HOSTNAME_LOOKUP
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
swig
public int swig()- Returns:
- the native value.
-
nativeName
-
fromSwig
- Parameters:
swigValue- the native value- Returns:
- the swig enum.
-
fromSwig
- Parameters:
swigValue- the native enum- Returns:
- the swig enum.
-