diff --git a/src/browser/fake_network.js b/src/browser/fake_network.js index 86b7ba5306..33d99505e0 100644 --- a/src/browser/fake_network.js +++ b/src/browser/fake_network.js @@ -900,45 +900,45 @@ function make_packet(spec) { function fake_tcp_connect(dport, adapter) { - // TODO: check port collisions - let sport = 49152 + Math.floor(Math.random() * 1000); - let tuple = [ - adapter.vm_ip.join("."), - dport, - adapter.router_ip.join("."), - sport - ].join(":"); - - let reader; - let connector; - - let conn = new TCPConnection(); - conn.net = adapter; - conn.on_data = function(data) { if(reader) reader.call(handle, data); }; - conn.on_connect = function() { if(connector) connector.call(handle); }; - conn.tuple = tuple; - - conn.hsrc = adapter.router_mac; - conn.psrc = adapter.router_ip; - conn.sport = sport; - conn.hdest = adapter.vm_mac; - conn.dport = dport; - conn.pdest = adapter.vm_ip; - - adapter.tcp_conn[tuple] = conn; - conn.connect(); - - // TODO: Real event source - let handle = { - write: function(data) { conn.write(data); }, - on: function(event, cb) { - if( event === "data" ) reader = cb; - if( event === "connect" ) connector = cb; - }, - close: function() { conn.close(); } - }; + // TODO: check port collisions + let sport = 49152 + Math.floor(Math.random() * 1000); + let tuple = [ + adapter.vm_ip.join("."), + dport, + adapter.router_ip.join("."), + sport + ].join(":"); + + let reader; + let connector; + + let conn = new TCPConnection(); + conn.net = adapter; + conn.on_data = function(data) { if(reader) reader.call(handle, data); }; + conn.on_connect = function() { if(connector) connector.call(handle); }; + conn.tuple = tuple; + + conn.hsrc = adapter.router_mac; + conn.psrc = adapter.router_ip; + conn.sport = sport; + conn.hdest = adapter.vm_mac; + conn.dport = dport; + conn.pdest = adapter.vm_ip; + + adapter.tcp_conn[tuple] = conn; + conn.connect(); + + // TODO: Real event source + let handle = { + write: function(data) { conn.write(data); }, + on: function(event, cb) { + if( event === "data" ) reader = cb; + if( event === "connect" ) connector = cb; + }, + close: function() { conn.close(); } + }; - return handle; + return handle; } /**