Enum Class Operation

java.lang.Object
java.lang.Enum<Operation>
com.frostwire.jlibtorrent.Operation
All Implemented Interfaces:
Serializable, Comparable<Operation>, Constable

public enum Operation extends Enum<Operation>
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:
  • Enum Constant Details

    • UNKNOWN

      public static final Operation UNKNOWN
      The error was unexpected and it is unknown which operation caused it.
    • BITTORRENT

      public static final Operation BITTORRENT
      This is used when the bittorrent logic determines to disconnect.
    • IOCONTROL

      public static final Operation IOCONTROL
      A call to iocontrol failed.
    • GETPEERNAME

      public static final Operation GETPEERNAME
      A call to getpeername failed (querying the remote IP of a connection).
    • GETNAME

      public static final Operation GETNAME
      A call to getname failed (querying the local IP of a connection).
    • ALLOC_RECVBUF

      public static final Operation ALLOC_RECVBUF
      An attempt to allocate a receive buffer failed.
    • ALLOC_SNDBUF

      public static final Operation ALLOC_SNDBUF
      An attempt to allocate a send buffer failed.
    • FILE_WRITE

      public static final Operation FILE_WRITE
      Writing to a file failed.
    • FILE_READ

      public static final Operation FILE_READ
      Reading from a file failed.
    • FILE

      public static final Operation FILE
      A non-read and non-write file operation failed.
    • SOCK_WRITE

      public static final Operation SOCK_WRITE
      A socket write operation failed.
    • SOCK_READ

      public static final Operation SOCK_READ
      A socket read operation failed.
    • SOCK_OPEN

      public static final Operation SOCK_OPEN
      A call to open(), to create a socket socket failed.
    • SOCK_BIND

      public static final Operation SOCK_BIND
      A call to bind() on a socket failed.
    • AVAILABLE

      public static final Operation AVAILABLE
      An attempt to query the number of bytes available to read from a socket failed.
    • ENCRYPTION

      public static final Operation ENCRYPTION
      A call related to bittorrent protocol encryption failed.
    • CONNECT

      public static final Operation CONNECT
      An attempt to connect a socket failed.
    • SSL_HANDSHAKE

      public static final Operation SSL_HANDSHAKE
      Establishing an SSL connection failed.
    • GET_INTERFACE

      public static final Operation GET_INTERFACE
      A connection failed to satisfy the bind interface setting.
    • SOCK_LISTEN

      public static final Operation SOCK_LISTEN
      A call to listen() on a socket.
    • SOCK_BIND_TO_DEVICE

      public static final Operation SOCK_BIND_TO_DEVICE
      A call to the ioctl to bind a socket to a specific network device or adaptor.
    • SOCK_ACCEPT

      public static final Operation SOCK_ACCEPT
      A call to accept() on a socket.
    • PARSE_ADDRESS

      public static final Operation PARSE_ADDRESS
      Convert a string into a valid network address.
    • ENUM_IF

      public static final Operation ENUM_IF
      Enumeration network devices or adapters.
    • FILE_STAT

      public static final Operation FILE_STAT
    • FILE_COPY

      public static final Operation FILE_COPY
    • FILE_FALLOCATE

      public static final Operation FILE_FALLOCATE
    • FILE_REMOVE

      public static final Operation FILE_REMOVE
    • FILE_RENAME

      public static final Operation FILE_RENAME
    • FILE_OPEN

      public static final Operation FILE_OPEN
    • MKDIR

      public static final Operation MKDIR
    • CHECK_RESUME

      public static final Operation CHECK_RESUME
    • EXCEPTION

      public static final Operation EXCEPTION
    • ALLOC_CACHE_PIECE

      public static final Operation ALLOC_CACHE_PIECE
    • PARTFILE_MOVE

      public static final Operation PARTFILE_MOVE
    • PARTFILE_READ

      public static final Operation PARTFILE_READ
    • PARTFILE_WRITE

      public static final Operation PARTFILE_WRITE
    • HOSTNAME_LOOKUP

      public static final Operation HOSTNAME_LOOKUP
  • Method Details

    • values

      public static Operation[] 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

      public static Operation valueOf(String name)
      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 name
      NullPointerException - if the argument is null
    • swig

      public int swig()
      Returns:
      the native value.
    • nativeName

      public String nativeName()
    • fromSwig

      public static Operation fromSwig(int swigValue)
      Parameters:
      swigValue - the native value
      Returns:
      the swig enum.
    • fromSwig

      public static Operation fromSwig(com.frostwire.jlibtorrent.swig.operation_t swigValue)
      Parameters:
      swigValue - the native enum
      Returns:
      the swig enum.