Changeset 74fac4b


Ignore:
Timestamp:
Nov 29, 2015 12:19:48 AM (5 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
d5717ca
Parents:
a5a7027
Message:

i2psnark: BEP 21 support (upload_only)

Location:
apps/i2psnark/java/src/org/klomp/snark
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • apps/i2psnark/java/src/org/klomp/snark/ExtensionHandler.java

    ra5a7027 r74fac4b  
    4343   *  @return bencoded outgoing handshake message
    4444   */
    45     public static byte[] getHandshake(int metasize, boolean pexAndMetadata, boolean dht) {
     45    public static byte[] getHandshake(int metasize, boolean pexAndMetadata, boolean dht, boolean uploadOnly) {
    4646        Map<String, Object> handshake = new HashMap<String, Object>();
    4747        Map<String, Integer> m = new HashMap<String, Integer>();
     
    6060        handshake.put("v", "I2PSnark");
    6161        handshake.put("reqq", Integer.valueOf(5));
     62        // BEP 21
     63        if (uploadOnly)
     64            handshake.put("upload_only", Integer.valueOf(1));
    6265        return BEncoder.bencode(handshake);
    6366    }
  • apps/i2psnark/java/src/org/klomp/snark/Peer.java

    ra5a7027 r74fac4b  
    218218   * If the given BitField is non-null it is send to the peer as first
    219219   * message.
    220    */
    221   public void runConnection(I2PSnarkUtil util, PeerListener listener, BitField bitfield, MagnetState mState)
    222   {
     220   *
     221   * @param uploadOnly if we are complete with skipped files, i.e. a partial seed
     222   */
     223  public void runConnection(I2PSnarkUtil util, PeerListener listener, BitField bitfield,
     224                            MagnetState mState, boolean uploadOnly) {
    223225    if (state != null)
    224226      throw new IllegalStateException("Peer already started");
     
    276278            boolean pexAndMetadata = metainfo == null || !metainfo.isPrivate();
    277279            boolean dht = util.getDHT() != null;
    278             out.sendExtension(0, ExtensionHandler.getHandshake(metasize, pexAndMetadata, dht));
     280            out.sendExtension(0, ExtensionHandler.getHandshake(metasize, pexAndMetadata, dht, uploadOnly));
    279281        }
    280 
    281         // Old DHT PORT message
    282         //if ((options & OPTION_I2P_DHT) != 0 && util.getDHT() != null) {
    283         //    if (_log.shouldLog(Log.DEBUG))
    284         //        _log.debug("Peer supports DHT, sending PORT message");
    285         //    int port = util.getDHT().getPort();
    286         //    out.sendPort(port);
    287         //}
    288282
    289283        // Send our bitmap
  • apps/i2psnark/java/src/org/klomp/snark/PeerCoordinator.java

    ra5a7027 r74fac4b  
    605605        else
    606606            bitfield = null;
     607        // if we aren't a seed but we don't want any more
     608        final boolean partialComplete = wantedBytes == 0 && bitfield != null && !bitfield.complete();
    607609        Runnable r = new Runnable()
    608610          {
    609611            public void run()
    610612            {
    611               peer.runConnection(_util, listener, bitfield, magnetState);
     613              peer.runConnection(_util, listener, bitfield, magnetState, partialComplete);
    612614            }
    613615          };
Note: See TracChangeset for help on using the changeset viewer.