From: Victor Grishchenko Date: Tue, 22 Jun 2010 12:18:17 +0000 (+0200) Subject: Sample HTTP gateway adjustments X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=500624c77f6ec5272aa01f19c5c30b9edc7f37b2;p=swift-upb.git Sample HTTP gateway adjustments --- diff --git a/README b/README index 8939346..37073d7 100644 --- a/README +++ b/README @@ -13,12 +13,21 @@ see doc/index.html for marketing stuff, ideas and rants d1502706c46779d361a1d562a10da0a45c4c40e5 -f \ trailer.ogg - ...to retrieve video and save it to a file, or... + ...to retrieve video and save it to a file. - ./swift -t mfold.libswift.org:20000 -h \ - d1502706c46779d361a1d562a10da0a45c4c40e5 -r . \ - -h 8080 - - ...and then point your browser at - - http://localhost:8080/d1502706c46779d361a1d562a10da0a45c4c40e5 + Alternatively, you might play with the HTTP gateway, the preliminary + version. First, run the seeder-tracker: + + $ ./swift -f ~/Downloads/big_buck_bunny_480p_stereo.ogg -l 0.0.0.0:20000 + Root hash: 7c462ad1d980ba44ab4b819e29004eb0bf6e6d5f + + ...then you may try running the swift-HTTP gateway... + + ./swift -t localhost:20000 -g 0.0.0.0:8080 -w + + ...and finally you may point your browser at the gateway... + + http://localhost:8080/7c462ad1d980ba44ab4b819e29004eb0bf6e6d5f + + If you use an HTML5 browser (Chrome preferred), you are likely to see + the bunny trailer at this point... diff --git a/httpgw.cpp b/httpgw.cpp index 6ad86e2..970c9f2 100644 --- a/httpgw.cpp +++ b/httpgw.cpp @@ -76,7 +76,8 @@ void HttpGwMayWriteCallback (SOCKET sink) { } else { if (req->tosend==0) { // done; wait for new request dprintf("%s @%i done\n",tintstr(),req->id); - sckrwecb_t wait_new_req(req->sink,HttpGwNewRequestCallback,NULL,HttpGwCloseConnection); + sckrwecb_t wait_new_req + (req->sink,HttpGwNewRequestCallback,NULL,HttpGwCloseConnection); swift::Datagram::Listen3rdPartySocket (wait_new_req); } else { // wait for data dprintf("%s @%i waiting for data\n",tintstr(),req->id); @@ -93,7 +94,8 @@ void HttpGwSwiftProgressCallback (int transfer, bin64_t bin) { if ( (bin.base_offset()<<10) == http_requests[httpc].offset ) { dprintf("%s @%i progress: %s\n",tintstr(),http_requests[httpc].id,bin.str()); sckrwecb_t maywrite_callbacks - (http_requests[httpc].sink,NULL,HttpGwMayWriteCallback,HttpGwCloseConnection); + (http_requests[httpc].sink,NULL, + HttpGwMayWriteCallback,HttpGwCloseConnection); Datagram::Listen3rdPartySocket (maywrite_callbacks); } } @@ -113,7 +115,7 @@ void HttpGwFirstProgressCallback (int transfer, bin64_t bin) { "HTTP/1.1 200 OK\r\n"\ "Connection: keep-alive\r\n"\ "Content-Type: video/ogg\r\n"\ - "X-Content-Duration: 32\r\n"\ + /*"X-Content-Duration: 32\r\n"*/\ "Content-Length: %lli\r\n"\ "Accept-Ranges: bytes\r\n"\ "\r\n", diff --git a/swift.cpp b/swift.cpp index e391520..6ea86ff 100644 --- a/swift.cpp +++ b/swift.cpp @@ -39,7 +39,7 @@ int main (int argc, char** argv) { Address bindaddr; Address tracker; Address http_gw; - tint wait_time = -1; + tint wait_time = 0; LibraryInit(); @@ -64,8 +64,7 @@ int main (int argc, char** argv) { bindaddr = Address(optarg); if (bindaddr==Address()) quit("address must be hostname:port, ip:port or just port\n"); - if (wait_time==-1) - wait_time = TINT_NEVER; // seed + wait_time = TINT_NEVER; break; case 't': tracker = Address(optarg); @@ -85,7 +84,6 @@ int main (int argc, char** argv) { wait_time = TINT_NEVER; // seed break; case 'w': - wait_time = TINT_NEVER; if (optarg) { char unit = 'u'; if (sscanf(optarg,"%lli%c",&wait_time,&unit)!=2) @@ -99,7 +97,8 @@ int main (int argc, char** argv) { case 'u': break; default: quit("time format: 1234[umsMHD], e.g. 1D = one day\n"); } - } + } else + wait_time = TINT_NEVER; break; } @@ -136,7 +135,7 @@ int main (int argc, char** argv) { printf("Root hash: %s\n", RootMerkleHash(file).hex().c_str()); } - if (bindaddr==Address() && file==-1) { + if (bindaddr==Address() && file==-1 && http_gw==Address()) { fprintf(stderr,"Usage:\n"); fprintf(stderr," -h, --hash\troot Merkle hash for the transmission\n"); fprintf(stderr," -f, --file\tname of file to use (root hash by default)\n"); @@ -146,13 +145,13 @@ int main (int argc, char** argv) { fprintf(stderr," -p, --progress\treport transfer progress\n"); fprintf(stderr," -g, --http\t[ip:|host:]port to bind HTTP gateway to (default localhost:8080)\n"); fprintf(stderr," -w, --wait\tlimit running time, e.g. 1[DHMs] (default: infinite with -l, -g)\n"); + return 1; } tint start_time = NOW; - while ( bindaddr!=Address() && - ( ( file>=0 && !IsComplete(file) ) || - ( start_time+wait_time > NOW ) ) ) { + while ( (file>=0 && !IsComplete(file)) || + (start_time+wait_time>NOW) ) { swift::Loop(TINT_SEC); if (report_progress && file>=0) { fprintf(stderr,