Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Basic support for LTEP (BEP 10).

  • Loading branch information...
commit df04b4ae37cbf2b6c1a285cc5d5bf3e346456093 1 parent 7fde0bd
Juliusz Chroboczek jech authored

Showing 2 changed files with 42 additions and 2 deletions. Show diff stats Hide diff stats

  1. +41 2 server.cpc
  2. +1 0  server.h
43 server.cpc
@@ -222,6 +222,35 @@ send_dht_port(int fd, unsigned short port)
222 222 return 0;
223 223 }
224 224
  225 +cps int
  226 +send_ltep_message(int fd, int id, char *body, int bodylen)
  227 +{
  228 + char buf[1];
  229 + buf[0] = id;
  230 +
  231 + return send_message_2(fd, 20, buf, 1, body, bodylen);
  232 +}
  233 +
  234 +cps int
  235 +send_ltep_handshake(int fd, unsigned short port)
  236 +{
  237 + int rc;
  238 + unsigned char buf[100];
  239 + const char *hekate = "Hekate 0.0";
  240 +
  241 + rc = snprintf(buf, 100, "d1:pi%ue1:v%d:%se",
  242 + port, (int)strlen(hekate), hekate);
  243 + if(rc < 0 || rc > 100)
  244 + return -1;
  245 +
  246 + rc = send_ltep_message(fd, 0, buf, rc);
  247 + if(rc < 0) {
  248 + perror("(send_ltep_handshake)cpc_full_write");
  249 + return -1;
  250 + }
  251 + return 0;
  252 +}
  253 +
225 254 void *
226 255 map_file(struct torrent *t, int index)
227 256 {
@@ -519,6 +548,7 @@ handshake(hashtable *ht , int fd)
519 548 memset(tmp, 0, 8);
520 549 if(!nodht)
521 550 tmp[7] |= 1;
  551 + tmp[5] |= 0x10;
522 552 tmp += 8;
523 553
524 554 memcpy(tmp, torrent->info_hash, 20);
@@ -540,13 +570,16 @@ handshake(hashtable *ht , int fd)
540 570 }
541 571
542 572 peers[fd].dht = !!(t[1 + 19 + 7] & 1);
  573 + peers[fd].ltep = !!(t[1 + 19 + 5] & 0x10);
543 574
544 575 debugf(2, "%3d peer-id ", fd);
545 576 for(i = 0; i < 20; i++) {
546 577 unsigned char c = t[48 + i];
547 578 debugf(2, "%c", c >= 0x21 && c <= 0x7E ? c : '.');
548 579 }
549   - debugf(2, "%s\n", peers[fd].dht ? " (DHT)" : "");
  580 + debugf(2, "%s%s\n",
  581 + peers[fd].dht ? " (DHT)" : "",
  582 + peers[fd].ltep ? " (LTEP)" : "");
550 583
551 584 return 0;
552 585 }
@@ -573,6 +606,12 @@ stream_writer(int fd)
573 606 }
574 607 }
575 608
  609 + if(peers[fd].ltep) {
  610 + rc = send_ltep_handshake(fd, peer_port);
  611 + if(rc < 0)
  612 + goto done;
  613 + }
  614 +
576 615 while(1) {
577 616 assert(!peers[fd].unchoked);
578 617
@@ -750,7 +789,7 @@ stream_reader(int fd)
750 789 }
751 790
752 791 switch(type) {
753   - case 0: case 1: case 4: case 5: case 9:
  792 + case 0: case 1: case 4: case 5: case 9: case 20:
754 793 break;
755 794
756 795 case 2:
1  server.h
@@ -36,6 +36,7 @@ typedef struct peer {
36 36 cpc_barrier *barrier;
37 37 struct torrent *t;
38 38 int dht;
  39 + int ltep;
39 40 int dying;
40 41 int interested;
41 42 int unchoked;

0 comments on commit df04b4a

Please sign in to comment.
Something went wrong with that request. Please try again.