wjzz avatar wjzz committed 4ece611 Draft

Generalized port numbers.

Comments (0)

Files changed (4)

+==========
+Change log
+==========
+
+***************************************
+from downloaded-possible-alpha-0 to tip
+***************************************
+
+internal:
+  * generalized HTTP-Server's PortNo        
 0. rethink again the state transitions for the peer in peer.erl - it's badly written
 1. send 'keep-alive' msgs every 2 seconds
 2. enable listening for new connections
-3. do something when the hash-test becomes false
 4. keep stats so we can see which seeders are 'fast'
 5. the 'bitfield' doesn't work for small files - fix this
+
+partly done:
+3. do something when the hash-test becomes false
 %%======================================%%
 
 start_listener(MetaInfo, PortNo) ->
+    catch(unregister(listener)),
     Pid = spawn(fun() -> listener_loop(MetaInfo, PortNo) end),
     register(listener, Pid).                         
 

Erlang/torrent.erl

 %%=====================%%
 
 start() ->
-    catch(unregister(worker)),
-    catch(unregister(listener)),
-    download_torrent(metadata:multi()).
+    start(9999).
+
+start(MonitorPortNo) ->
+    download_torrent(MonitorPortNo, metadata:multi()).
 
 %%======================================================%%
 %%  Top-level functions that starts the whole business  %%
 %%======================================================%%
 
-download_torrent(MetaInfo) ->
+download_torrent(MonitorPortNo, MetaInfo) ->
     metadata:pretty(MetaInfo),
     
     %% Start processes working in the background
     %% 
     %%start_timer(5),
     %%peer:start_listener(MetaInfo, 9999),
-    http_server:start(8888, http_server, fun logging:router/1),
+    http_server:start(MonitorPortNo, http_server, fun logging:router/1),
 
     log({metainfo, MetaInfo}),
 
 %% with the newly found peers.
 
 start_worker(MetaInfo) ->
+    catch(unregister(worker)),
     Pid = spawn(fun () -> worker_loop(MetaInfo) end),
     register(worker, Pid).
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.