github.com/uber/kraken@v0.1.4/proto/p2p/p2p.proto (about)

     1  /*
     2    P2PMessage represents a flavor of a P2P torrent protocol that kraken supports
     3  */
     4  
     5  syntax = "proto3";
     6  
     7  package p2p;
     8  
     9  // Binary set of all pieces that peer has downloaded so far. Also serves as a
    10  // handshaking message, which each peer sends once at the beginning of the
    11  // connection to declare what their peer id is and what info hash they want to
    12  // transmit.
    13  message BitfieldMessage {
    14      string infoHash = 2;
    15      // TODO: Torrent name is the content hash. Current torrent storage is 
    16      // content addressable. Adding name as a part of handshake makes looking  
    17      // up torrents faster. If storage supports addressing torrent by infohash, 
    18      // this extra field should removed. 
    19      // XXX(codyg): We rely on this name field for announcing too, so tracker can
    20      // look up origins that have this content.
    21      // We currently treat infohash as verification of torrents.
    22      string name          = 3;
    23      string peerID        = 4;
    24      bytes  bitfieldBytes = 5;
    25      string namespace     = 6;
    26  
    27      // remoteBitfieldBytes contains the binary sets of pieces downloaded of
    28      // all peers that the sender is currently connected to.
    29      map<string, bytes> remoteBitfieldBytes = 7;
    30  }
    31  
    32  // Requests a piece of the given index. Note: offset and length are unused fields
    33  // and if set, will be rejected.
    34  message PieceRequestMessage {
    35      int32 index  = 2;
    36      int32 offset = 3; // Unused.
    37      int32 length = 4; // Unused.
    38  }
    39  
    40  // Provides binary payload response to a peer request. Always immediately followed
    41  // by a binary blob sent over socket, so the receiver should be ready to treat the
    42  // blob as a non-protobuf message.
    43  message PiecePayloadMessage {
    44      int32  index  = 2;
    45      int32  offset = 3; // Unused.
    46      int32  length = 4; // Unused.
    47      string digest = 5; // Cryptographic signature of a piece content (sha1, md5).
    48  }
    49  
    50  // Announces that a piece is available to other peers.
    51  message AnnouncePieceMessage {
    52      int32 index = 2;
    53  }
    54  
    55  // Unused.
    56  message CancelPieceMessage {
    57      int32 index = 2;
    58  }
    59  
    60  // General purpose error message. Receivers may check the error code to determine
    61  // the origin of the message.
    62  message ErrorMessage {
    63  
    64      enum ErrorCode {
    65          PIECE_REQUEST_FAILED = 0;
    66      }
    67  
    68      string    error = 2;
    69      int32     index = 3;
    70      ErrorCode code  = 4;
    71  }
    72  
    73  // Notifies other peers that the torrent has completed and all pieces are available.
    74  message CompleteMessage {}
    75  
    76  message Message {
    77  
    78      enum Type {
    79          BITFIELD      = 0;
    80          PIECE_REQUEST = 1;
    81          PIECE_PAYLOAD = 2;
    82          ANNOUCE_PIECE = 3;
    83          CANCEL_PIECE  = 4;
    84          ERROR         = 5;
    85          COMPLETE      = 6;
    86      }
    87  
    88      string version = 1;
    89  
    90      Type type = 2;
    91  
    92      BitfieldMessage      bitfield      = 3;
    93      PieceRequestMessage  pieceRequest  = 4;
    94      PiecePayloadMessage  piecePayload  = 5;
    95      AnnouncePieceMessage announcePiece = 6;
    96      CancelPieceMessage   cancelPiece   = 7;
    97      ErrorMessage         error         = 8;
    98      CompleteMessage      complete      = 9;
    99  }