shithub: riscv

Download patch

ref: 1c31521e2d4a0026c406a536efcb78d4660c9ebe
parent: 4ebf90dff07e3ada0cc4e26efbb0064542c0d4c9
author: cinap_lenrek <cinap_lenrek@centraldogma>
date: Mon Oct 24 15:24:47 EDT 2011

torrent: fix trailing amp in announce url

--- a/sys/src/cmd/ip/torrent.c
+++ b/sys/src/cmd/ip/torrent.c
@@ -355,9 +355,9 @@
 				return 1;
 			if(memcmp(buf, "\x13BitTorrent protocol", 20))
 				return 0;
-			if(debug) fprint(2, "peer %s: <- handshake\n", addr);
 			if(memcmp(infohash, buf + 20 + 8, sizeof(infohash)))
 				return 0;
+			if(debug) fprint(2, "peer %s: <- handshake\n", addr);
 		}
 	}
 	if(readn(fd, buf, sizeof(peerid)) != sizeof(peerid))
@@ -376,7 +376,7 @@
 
 	if(debug) fprint(2, "peer %s: -> bitfield %d\n", addr, nhavemap);
 	memmove(told, havemap, nhavemap);
-	n = pack(buf, sizeof(buf), "lb*", nhavemap+1, 0x05, nhavemap, havemap);
+	n = pack(buf, sizeof(buf), "lb*", nhavemap+1, 0x05, nhavemap, told);
 	if(write(fd, buf, n) != n)
 		goto Out;
 
@@ -679,7 +679,7 @@
 	if(rfork(RFPROC|RFMEM))
 		return;
 
-	event = "event=started";
+	event = "&event=started";
 	for(;;){
 		vlong up, down, left;
 
@@ -691,7 +691,7 @@
 
 		d = nil;
 		if((fd = hopen("%s?info_hash=%.*H&peer_id=%.*H&port=%d&"
-			"uploaded=%lld&downloaded=%lld&left=%lld&compact=1&no_peer_id=1&%s",
+			"uploaded=%lld&downloaded=%lld&left=%lld&compact=1&no_peer_id=1%s",
 			url, sizeof(infohash), infohash, sizeof(peerid), peerid, port,
 			up, down, left, event)) >= 0){
 			event = "";