v86 0.5.325 → 0.5.326

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3516,12 +3516,12 @@ function $handle_fake_networking$$module$src$browser$fake_network$$($arp$jscomp$
3516
3516
  $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.state = "syn-received";
3517
3517
  $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.tuple = $arp$jscomp$inline_346_bop$jscomp$inline_84_data$jscomp$118_icmp$jscomp$inline_336_now_n$jscomp$inline_93_packet_subnet$jscomp$inline_108_payload$jscomp$inline_78_reply$jscomp$inline_100_reply$jscomp$inline_104_reply$jscomp$inline_110_reply$jscomp$inline_350_tcp$jscomp$inline_338_tuple$jscomp$inline_82_udp$jscomp$inline_341_view$jscomp$inline_335_view$jscomp$inline_340$$;
3518
3518
  $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.last = $packet$jscomp$6$$;
3519
- $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.hsrc = $packet$jscomp$6$$.eth.dest;
3520
- $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.psrc = $packet$jscomp$6$$.ipv4.dest;
3519
+ $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.hsrc = new Uint8Array($packet$jscomp$6$$.eth.dest);
3520
+ $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.psrc = new Uint8Array($packet$jscomp$6$$.ipv4.dest);
3521
3521
  $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.sport = $packet$jscomp$6$$.tcp.dport;
3522
- $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.hdest = $packet$jscomp$6$$.eth.src;
3522
+ $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.hdest = new Uint8Array($packet$jscomp$6$$.eth.src);
3523
3523
  $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.dport = $packet$jscomp$6$$.tcp.sport;
3524
- $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.pdest = $packet$jscomp$6$$.ipv4.src;
3524
+ $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.pdest = new Uint8Array($packet$jscomp$6$$.ipv4.src);
3525
3525
  $adapter$jscomp$6$$.bus.pair.send("tcp-connection", $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$);
3526
3526
  if ($adapter$jscomp$6$$.on_tcp_connection) {
3527
3527
  $adapter$jscomp$6$$.on_tcp_connection($answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$, $packet$jscomp$6$$);
@@ -3515,12 +3515,12 @@ function $handle_fake_networking$$module$src$browser$fake_network$$($arp$jscomp$
3515
3515
  $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.state = "syn-received";
3516
3516
  $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.tuple = $arp$jscomp$inline_346_bop$jscomp$inline_84_data$jscomp$118_icmp$jscomp$inline_336_now_n$jscomp$inline_93_packet_subnet$jscomp$inline_108_payload$jscomp$inline_78_reply$jscomp$inline_100_reply$jscomp$inline_104_reply$jscomp$inline_110_reply$jscomp$inline_350_tcp$jscomp$inline_338_tuple$jscomp$inline_82_udp$jscomp$inline_341_view$jscomp$inline_335_view$jscomp$inline_340$$;
3517
3517
  $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.last = $packet$jscomp$6$$;
3518
- $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.hsrc = $packet$jscomp$6$$.eth.dest;
3519
- $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.psrc = $packet$jscomp$6$$.ipv4.dest;
3518
+ $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.hsrc = new Uint8Array($packet$jscomp$6$$.eth.dest);
3519
+ $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.psrc = new Uint8Array($packet$jscomp$6$$.ipv4.dest);
3520
3520
  $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.sport = $packet$jscomp$6$$.tcp.dport;
3521
- $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.hdest = $packet$jscomp$6$$.eth.src;
3521
+ $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.hdest = new Uint8Array($packet$jscomp$6$$.eth.src);
3522
3522
  $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.dport = $packet$jscomp$6$$.tcp.sport;
3523
- $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.pdest = $packet$jscomp$6$$.ipv4.src;
3523
+ $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$.pdest = new Uint8Array($packet$jscomp$6$$.ipv4.src);
3524
3524
  $adapter$jscomp$6$$.bus.pair.send("tcp-connection", $answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$);
3525
3525
  if ($adapter$jscomp$6$$.on_tcp_connection) {
3526
3526
  $adapter$jscomp$6$$.on_tcp_connection($answers$jscomp$inline_351_conn$jscomp$inline_83_data$jscomp$inline_471_dhcp$jscomp$inline_465_ethertype$jscomp$inline_76_flags$jscomp$inline_339_now_n_f$jscomp$inline_94_proto$jscomp$inline_331_reply$jscomp$inline_85_router_subnet$jscomp$inline_109_view$jscomp$inline_337_view$jscomp$inline_345_view$jscomp$inline_464_view$jscomp$inline_473$$, $packet$jscomp$6$$);
package/build/libv86.js CHANGED
@@ -191,12 +191,12 @@ function Hb(a,b){let c={};var d=(new DataView(a.buffer,a.byteOffset,a.byteLength
191
191
  a.rst=!!(d&4),a.psh=!!(d&8),a.ack=!!(d&16),a.urg=!!(d&32),a.ece=!!(d&64),a.cwr=!!(d&128),c.tcp=a,c.tcp_data=e.subarray(4*a.doff);else if(17===d){a=new DataView(e.buffer,e.byteOffset,e.byteLength);a={sport:a.getUint16(0),dport:a.getUint16(2),len:a.getUint16(4),checksum:a.getUint16(6),data:e.subarray(8),data_s:(new TextDecoder).decode(e.subarray(8))};if(67===a.dport||67===a.sport){e=e.subarray(8);d=new DataView(e.buffer,e.byteOffset,e.byteLength);e.subarray(44,236);d={op:d.getUint8(0),htype:d.getUint8(1),
192
192
  hlen:d.getUint8(2),hops:d.getUint8(3),xid:d.getUint32(4),secs:d.getUint16(8),flags:d.getUint16(10),ciaddr:d.getUint32(12),yiaddr:d.getUint32(16),siaddr:d.getUint32(20),giaddr:d.getUint32(24),chaddr:e.subarray(28,44),magic:d.getUint32(236),options:[]};e=e.subarray(240);for(l=0;l<e.length;++l)g=l,0!==e[l]&&(++l,h=e[l],l+=h,d.options.push(e.subarray(g,g+h+2)));c.dhcp=d;c.dhcp_options=d.options}else 53===a.dport||53===a.sport?Ib(e.subarray(8),c):123===a.dport&&(d=e.subarray(8),d=new DataView(d.buffer,
193
193
  d.byteOffset,d.byteLength),c.ntp={flags:d.getUint8(0),stratum:d.getUint8(1),poll:d.getUint8(2),precision:d.getUint8(3),root_delay:d.getUint32(4),root_disp:d.getUint32(8),ref_id:d.getUint32(12),ref_ts_i:d.getUint32(16),ref_ts_f:d.getUint32(20),ori_ts_i:d.getUint32(24),ori_ts_f:d.getUint32(28),rec_ts_i:d.getUint32(32),rec_ts_f:d.getUint32(36),trans_ts_i:d.getUint32(40),trans_ts_f:d.getUint32(44)});c.udp=a}}else 2054===d?(d=new DataView(a.buffer,a.byteOffset,a.byteLength),a={htype:d.getUint16(0),ptype:d.getUint16(2),
194
- oper:d.getUint16(6),sha:a.subarray(8,14),spa:a.subarray(14,18),tha:a.subarray(18,24),tpa:a.subarray(24,28)},c.arp=a):34525!==d&&y(d);if(c.ipv4)if(c.tcp)a:{a=`${c.ipv4.src.join(".")}:${c.tcp.sport}:${c.ipv4.dest.join(".")}:${c.tcp.dport}`;if(c.tcp.syn&&!c.tcp.ack){b.tcp_conn[a]&&delete b.tcp_conn[a];d=new Jb(b);d.state="syn-received";d.tuple=a;d.last=c;d.hsrc=c.eth.dest;d.psrc=c.ipv4.dest;d.sport=c.tcp.dport;d.hdest=c.eth.src;d.dport=c.tcp.sport;d.pdest=c.ipv4.src;b.bus.pair.send("tcp-connection",
195
- d);if(b.on_tcp_connection)b.on_tcp_connection(d,c);if(b.tcp_conn[a])break a}if(b.tcp_conn[a])b.tcp_conn[a].process(c);else{a=c.tcp.ackn;if(c.tcp.fin||c.tcp.syn)a+=1;d={};d.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src};d.ipv4={proto:6,src:c.ipv4.dest,dest:c.ipv4.src};d.tcp={sport:c.tcp.dport,dport:c.tcp.sport,seq:a,ackn:c.tcp.seq+(c.tcp.syn?1:0),winsize:c.tcp.winsize,rst:!0,ack:c.tcp.syn};b.receive(Eb(b.eth_encoder_buf,d))}}else if(c.udp)if(c.dns)if("static"===b.dns_method){a={};a.eth={ethertype:2048,
196
- src:b.router_mac,dest:c.eth.src};a.ipv4={proto:17,src:b.router_ip,dest:c.ipv4.src};a.udp={sport:53,dport:c.udp.sport};d=[];for(e=0;e<c.dns.questions.length;++e)switch(l=c.dns.questions[e],l.type){case 1:d.push({name:l.name,type:l.type,class:l.class,ttl:600,data:[192,168,87,1]})}a.dns={id:c.dns.id,flags:33152,questions:c.dns.questions,answers:d};b.receive(Eb(b.eth_encoder_buf,a))}else Fb(c,b);else c.dhcp?Gb(c,b):c.ntp?(a=Date.now()+rb,d=a%1E3/1E3*wb,e={},e.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},
197
- e.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},e.udp={sport:123,dport:c.udp.sport},e.ntp=Object.assign({},c.ntp),e.ntp.flags=36,e.ntp.poll=10,e.ntp.ori_ts_i=c.ntp.trans_ts_i,e.ntp.ori_ts_f=c.ntp.trans_ts_f,e.ntp.rec_ts_i=a/1E3,e.ntp.rec_ts_f=d,e.ntp.trans_ts_i=a/1E3,e.ntp.trans_ts_f=d,e.ntp.stratum=2,b.receive(Eb(b.eth_encoder_buf,e))):8===c.udp.dport&&(a={},a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},a.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},a.udp={sport:c.udp.dport,dport:c.udp.sport,
198
- data:(new TextEncoder).encode(c.udp.data_s)},b.receive(Eb(b.eth_encoder_buf,a)));else c.icmp&&8===c.icmp.type&&(a={},a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},a.ipv4={proto:1,src:c.ipv4.dest,dest:c.ipv4.src},a.icmp={type:0,code:c.icmp.code,data:c.icmp.data},b.receive(Eb(b.eth_encoder_buf,a)));else c.arp&&1===c.arp.oper&&2048===c.arp.ptype&&(a=zb(c.arp.tpa)&4294967040,d=zb(b.router_ip)&4294967040,!b.masquerade&&a!==d||a===d&&99<c.arp.tpa[3]||(a={},a.eth={ethertype:2054,src:b.router_mac,
199
- dest:c.eth.src},a.arp={htype:1,ptype:2048,oper:2,sha:b.router_mac,spa:c.arp.tpa,tha:c.eth.src,tpa:c.arp.spa},b.receive(Eb(b.eth_encoder_buf,a))))}
194
+ oper:d.getUint16(6),sha:a.subarray(8,14),spa:a.subarray(14,18),tha:a.subarray(18,24),tpa:a.subarray(24,28)},c.arp=a):34525!==d&&y(d);if(c.ipv4)if(c.tcp)a:{a=`${c.ipv4.src.join(".")}:${c.tcp.sport}:${c.ipv4.dest.join(".")}:${c.tcp.dport}`;if(c.tcp.syn&&!c.tcp.ack){b.tcp_conn[a]&&delete b.tcp_conn[a];d=new Jb(b);d.state="syn-received";d.tuple=a;d.last=c;d.hsrc=new Uint8Array(c.eth.dest);d.psrc=new Uint8Array(c.ipv4.dest);d.sport=c.tcp.dport;d.hdest=new Uint8Array(c.eth.src);d.dport=c.tcp.sport;d.pdest=
195
+ new Uint8Array(c.ipv4.src);b.bus.pair.send("tcp-connection",d);if(b.on_tcp_connection)b.on_tcp_connection(d,c);if(b.tcp_conn[a])break a}if(b.tcp_conn[a])b.tcp_conn[a].process(c);else{a=c.tcp.ackn;if(c.tcp.fin||c.tcp.syn)a+=1;d={};d.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src};d.ipv4={proto:6,src:c.ipv4.dest,dest:c.ipv4.src};d.tcp={sport:c.tcp.dport,dport:c.tcp.sport,seq:a,ackn:c.tcp.seq+(c.tcp.syn?1:0),winsize:c.tcp.winsize,rst:!0,ack:c.tcp.syn};b.receive(Eb(b.eth_encoder_buf,d))}}else if(c.udp)if(c.dns)if("static"===
196
+ b.dns_method){a={};a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src};a.ipv4={proto:17,src:b.router_ip,dest:c.ipv4.src};a.udp={sport:53,dport:c.udp.sport};d=[];for(e=0;e<c.dns.questions.length;++e)switch(l=c.dns.questions[e],l.type){case 1:d.push({name:l.name,type:l.type,class:l.class,ttl:600,data:[192,168,87,1]})}a.dns={id:c.dns.id,flags:33152,questions:c.dns.questions,answers:d};b.receive(Eb(b.eth_encoder_buf,a))}else Fb(c,b);else c.dhcp?Gb(c,b):c.ntp?(a=Date.now()+rb,d=a%1E3/1E3*wb,e={},e.eth=
197
+ {ethertype:2048,src:b.router_mac,dest:c.eth.src},e.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},e.udp={sport:123,dport:c.udp.sport},e.ntp=Object.assign({},c.ntp),e.ntp.flags=36,e.ntp.poll=10,e.ntp.ori_ts_i=c.ntp.trans_ts_i,e.ntp.ori_ts_f=c.ntp.trans_ts_f,e.ntp.rec_ts_i=a/1E3,e.ntp.rec_ts_f=d,e.ntp.trans_ts_i=a/1E3,e.ntp.trans_ts_f=d,e.ntp.stratum=2,b.receive(Eb(b.eth_encoder_buf,e))):8===c.udp.dport&&(a={},a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},a.ipv4={proto:17,src:c.ipv4.dest,
198
+ dest:c.ipv4.src},a.udp={sport:c.udp.dport,dport:c.udp.sport,data:(new TextEncoder).encode(c.udp.data_s)},b.receive(Eb(b.eth_encoder_buf,a)));else c.icmp&&8===c.icmp.type&&(a={},a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},a.ipv4={proto:1,src:c.ipv4.dest,dest:c.ipv4.src},a.icmp={type:0,code:c.icmp.code,data:c.icmp.data},b.receive(Eb(b.eth_encoder_buf,a)));else c.arp&&1===c.arp.oper&&2048===c.arp.ptype&&(a=zb(c.arp.tpa)&4294967040,d=zb(b.router_ip)&4294967040,!b.masquerade&&a!==d||a===d&&
199
+ 99<c.arp.tpa[3]||(a={},a.eth={ethertype:2054,src:b.router_mac,dest:c.eth.src},a.arp={htype:1,ptype:2048,oper:2,sha:b.router_mac,spa:c.arp.tpa,tha:c.eth.src,tpa:c.arp.spa},b.receive(Eb(b.eth_encoder_buf,a))))}
200
200
  function Ib(a,b){function c(){let m=[],n;do n=d.getUint8(h),m.push((new TextDecoder).decode(a.subarray(h+1,h+1+n))),h+=n+1;while(0<n);return m}let d=new DataView(a.buffer,a.byteOffset,a.byteLength),e={id:d.getUint16(0),flags:d.getUint16(2),questions:[],answers:[]};var f=d.getUint16(4);let g=d.getUint16(6);d.getUint16(8);d.getUint16(10);let h=12;for(var l=0;l<f;l++)e.questions.push({name:c(),type:d.getInt16(h),class:d.getInt16(h+2)}),h+=4;for(f=0;f<g;f++){l={name:c(),type:d.getInt16(h),class:d.getUint16(h+
201
201
  2),ttl:d.getUint32(h+4)};h+=8;let m=d.getUint16(h);h+=2;l.data=a.subarray(h,h+m);h+=m;e.answers.push(l)}b.dns=e}
202
202
  function Tb(a,b){var c=b.vm_ip.join(".");const d=b.router_ip.join("."),e=16383*Math.random()|0;let f,g,h=0;do f=49152+(e+h)%16383,g=`${c}:${a}:${d}:${f}`;while(16383>++h&&b.tcp_conn[g]);if(b.tcp_conn[g])throw Error("pool of dynamic TCP port numbers exhausted, connection aborted");c=new Jb(b);c.tuple=g;c.hsrc=b.router_mac;c.psrc=b.router_ip;c.sport=f;c.hdest=b.vm_mac;c.dport=a;c.pdest=b.vm_ip;b.tcp_conn[g]=c;c.connect();return c}
package/build/libv86.mjs CHANGED
@@ -172,21 +172,21 @@ e.byteLength),a={type:a.getUint8(0),code:a.getUint8(1),checksum:a.getUint16(2),d
172
172
  e.subarray(4*a.doff);else if(17===d){a=new DataView(e.buffer,e.byteOffset,e.byteLength);a={sport:a.getUint16(0),dport:a.getUint16(2),len:a.getUint16(4),checksum:a.getUint16(6),data:e.subarray(8),data_s:(new TextDecoder).decode(e.subarray(8))};if(67===a.dport||67===a.sport){e=e.subarray(8);d=new DataView(e.buffer,e.byteOffset,e.byteLength);e.subarray(44,236);d={op:d.getUint8(0),htype:d.getUint8(1),hlen:d.getUint8(2),hops:d.getUint8(3),xid:d.getUint32(4),secs:d.getUint16(8),flags:d.getUint16(10),ciaddr:d.getUint32(12),
173
173
  yiaddr:d.getUint32(16),siaddr:d.getUint32(20),giaddr:d.getUint32(24),chaddr:e.subarray(28,44),magic:d.getUint32(236),options:[]};e=e.subarray(240);for(l=0;l<e.length;++l)g=l,0!==e[l]&&(++l,h=e[l],l+=h,d.options.push(e.subarray(g,g+h+2)));c.dhcp=d;c.dhcp_options=d.options}else 53===a.dport||53===a.sport?Ib(e.subarray(8),c):123===a.dport&&(d=e.subarray(8),d=new DataView(d.buffer,d.byteOffset,d.byteLength),c.ntp={flags:d.getUint8(0),stratum:d.getUint8(1),poll:d.getUint8(2),precision:d.getUint8(3),root_delay:d.getUint32(4),
174
174
  root_disp:d.getUint32(8),ref_id:d.getUint32(12),ref_ts_i:d.getUint32(16),ref_ts_f:d.getUint32(20),ori_ts_i:d.getUint32(24),ori_ts_f:d.getUint32(28),rec_ts_i:d.getUint32(32),rec_ts_f:d.getUint32(36),trans_ts_i:d.getUint32(40),trans_ts_f:d.getUint32(44)});c.udp=a}}else 2054===d?(d=new DataView(a.buffer,a.byteOffset,a.byteLength),a={htype:d.getUint16(0),ptype:d.getUint16(2),oper:d.getUint16(6),sha:a.subarray(8,14),spa:a.subarray(14,18),tha:a.subarray(18,24),tpa:a.subarray(24,28)},c.arp=a):34525!==d&&
175
- y(d);if(c.ipv4)if(c.tcp)a:{a=`${c.ipv4.src.join(".")}:${c.tcp.sport}:${c.ipv4.dest.join(".")}:${c.tcp.dport}`;if(c.tcp.syn&&!c.tcp.ack){b.tcp_conn[a]&&delete b.tcp_conn[a];d=new Jb(b);d.state="syn-received";d.tuple=a;d.last=c;d.hsrc=c.eth.dest;d.psrc=c.ipv4.dest;d.sport=c.tcp.dport;d.hdest=c.eth.src;d.dport=c.tcp.sport;d.pdest=c.ipv4.src;b.bus.pair.send("tcp-connection",d);if(b.on_tcp_connection)b.on_tcp_connection(d,c);if(b.tcp_conn[a])break a}if(b.tcp_conn[a])b.tcp_conn[a].process(c);else{a=c.tcp.ackn;
176
- if(c.tcp.fin||c.tcp.syn)a+=1;d={};d.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src};d.ipv4={proto:6,src:c.ipv4.dest,dest:c.ipv4.src};d.tcp={sport:c.tcp.dport,dport:c.tcp.sport,seq:a,ackn:c.tcp.seq+(c.tcp.syn?1:0),winsize:c.tcp.winsize,rst:!0,ack:c.tcp.syn};b.receive(Eb(b.eth_encoder_buf,d))}}else if(c.udp)if(c.dns)if("static"===b.dns_method){a={};a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src};a.ipv4={proto:17,src:b.router_ip,dest:c.ipv4.src};a.udp={sport:53,dport:c.udp.sport};d=[];for(e=
177
- 0;e<c.dns.questions.length;++e)switch(l=c.dns.questions[e],l.type){case 1:d.push({name:l.name,type:l.type,class:l.class,ttl:600,data:[192,168,87,1]})}a.dns={id:c.dns.id,flags:33152,questions:c.dns.questions,answers:d};b.receive(Eb(b.eth_encoder_buf,a))}else Fb(c,b);else c.dhcp?Gb(c,b):c.ntp?(a=Date.now()+rb,d=a%1E3/1E3*wb,e={},e.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},e.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},e.udp={sport:123,dport:c.udp.sport},e.ntp=Object.assign({},c.ntp),e.ntp.flags=
178
- 36,e.ntp.poll=10,e.ntp.ori_ts_i=c.ntp.trans_ts_i,e.ntp.ori_ts_f=c.ntp.trans_ts_f,e.ntp.rec_ts_i=a/1E3,e.ntp.rec_ts_f=d,e.ntp.trans_ts_i=a/1E3,e.ntp.trans_ts_f=d,e.ntp.stratum=2,b.receive(Eb(b.eth_encoder_buf,e))):8===c.udp.dport&&(a={},a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},a.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},a.udp={sport:c.udp.dport,dport:c.udp.sport,data:(new TextEncoder).encode(c.udp.data_s)},b.receive(Eb(b.eth_encoder_buf,a)));else c.icmp&&8===c.icmp.type&&(a={},
179
- a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},a.ipv4={proto:1,src:c.ipv4.dest,dest:c.ipv4.src},a.icmp={type:0,code:c.icmp.code,data:c.icmp.data},b.receive(Eb(b.eth_encoder_buf,a)));else c.arp&&1===c.arp.oper&&2048===c.arp.ptype&&(a=zb(c.arp.tpa)&4294967040,d=zb(b.router_ip)&4294967040,!b.masquerade&&a!==d||a===d&&99<c.arp.tpa[3]||(a={},a.eth={ethertype:2054,src:b.router_mac,dest:c.eth.src},a.arp={htype:1,ptype:2048,oper:2,sha:b.router_mac,spa:c.arp.tpa,tha:c.eth.src,tpa:c.arp.spa},b.receive(Eb(b.eth_encoder_buf,
180
- a))))}function Ib(a,b){function c(){let m=[],n;do n=d.getUint8(h),m.push((new TextDecoder).decode(a.subarray(h+1,h+1+n))),h+=n+1;while(0<n);return m}let d=new DataView(a.buffer,a.byteOffset,a.byteLength),e={id:d.getUint16(0),flags:d.getUint16(2),questions:[],answers:[]};var f=d.getUint16(4);let g=d.getUint16(6);d.getUint16(8);d.getUint16(10);let h=12;for(var l=0;l<f;l++)e.questions.push({name:c(),type:d.getInt16(h),class:d.getInt16(h+2)}),h+=4;for(f=0;f<g;f++){l={name:c(),type:d.getInt16(h),class:d.getUint16(h+
181
- 2),ttl:d.getUint32(h+4)};h+=8;let m=d.getUint16(h);h+=2;l.data=a.subarray(h,h+m);h+=m;e.answers.push(l)}b.dns=e}function Tb(a,b){var c=b.vm_ip.join(".");const d=b.router_ip.join("."),e=16383*Math.random()|0;let f,g,h=0;do f=49152+(e+h)%16383,g=`${c}:${a}:${d}:${f}`;while(16383>++h&&b.tcp_conn[g]);if(b.tcp_conn[g])throw Error("pool of dynamic TCP port numbers exhausted, connection aborted");c=new Jb(b);c.tuple=g;c.hsrc=b.router_mac;c.psrc=b.router_ip;c.sport=f;c.hdest=b.vm_mac;c.dport=a;c.pdest=b.vm_ip;
182
- b.tcp_conn[g]=c;c.connect();return c}function Ub(a,b){return new Promise(c=>{let d=Tb(a,b);d.state="syn-probe";d.on("probe",c)})}function Jb(a){this.mtu=a.mtu||1500;const b=this.mtu-20-20;this.state="closed";this.net=a;this.send_buffer=new Ab(2048,0);this.send_chunk_buf=new Uint8Array(b);this.delayed_send_fin=this.in_active_close=!1;this.delayed_state=void 0;this.events_handlers={}}Jb.prototype.on=function(a,b){this.events_handlers[a]=b};Jb.prototype.emit=function(a,...b){this.events_handlers[a]&&
183
- this.events_handlers[a].apply(this,b)};Jb.prototype.ipv4_reply=function(){let a={};a.eth={ethertype:2048,src:this.hsrc,dest:this.hdest};a.ipv4={proto:6,src:this.psrc,dest:this.pdest};a.tcp={sport:this.sport,dport:this.dport,winsize:this.winsize,ackn:this.ack,seq:this.seq,ack:!0};return a};Jb.prototype.packet_reply=function(a,b){a={sport:a.tcp.dport,dport:a.tcp.sport,winsize:a.tcp.winsize,ackn:this.ack,seq:this.seq};if(b)for(const c in b)a[c]=b[c];b=this.ipv4_reply();b.tcp=a;return b};Jb.prototype.connect=
184
- function(){this.seq=1338;this.ack=1;this.start_seq=0;this.winsize=64240;"syn-probe"!==this.state&&(this.state="syn-sent");let a=this.ipv4_reply();a.ipv4.id=2345;a.tcp={sport:this.sport,dport:this.dport,seq:1337,ackn:0,winsize:0,syn:!0};this.net.receive(Eb(this.net.eth_encoder_buf,a))};Jb.prototype.accept=function(a){a=a||this.last;this.net.tcp_conn[this.tuple]=this;this.seq=1338;this.ack=a.tcp.seq+1;this.start_seq=a.tcp.seq;this.winsize=a.tcp.winsize;let b=this.ipv4_reply();b.tcp={sport:this.sport,
185
- dport:this.dport,seq:1337,ackn:this.ack,winsize:a.tcp.winsize,syn:!0,ack:!0,options:{mss:this.mtu-20-20}};this.state="established";this.net.receive(Eb(this.net.eth_encoder_buf,b))};Jb.prototype.process=function(a){this.last=a;if("closed"===this.state)a=this.packet_reply(a,{rst:!0}),this.net.receive(Eb(this.net.eth_encoder_buf,a));else if(a.tcp.rst){if("syn-probe"===this.state)this.emit("probe",!1);else this.on_close();this.release()}else if(a.tcp.syn)"syn-sent"===this.state&&a.tcp.ack?(this.ack=a.tcp.seq+
186
- 1,this.start_seq=a.tcp.seq,this.last_received_ackn=a.tcp.ackn,a=this.ipv4_reply(),this.net.receive(Eb(this.net.eth_encoder_buf,a)),this.state="established",this.emit("connect")):"syn-probe"===this.state&&a.tcp.ack&&(this.emit("probe",!0),a=this.packet_reply(a,{rst:!0}),this.net.receive(Eb(this.net.eth_encoder_buf,a)),this.release());else{if(a.tcp.ack)if("syn-received"===this.state)this.state="established";else if("fin-wait-1"===this.state)a.tcp.fin||(this.state="fin-wait-2");else if("closing"===this.state||
187
- "last-ack"===this.state){this.release();return}if(void 0===this.last_received_ackn)this.last_received_ackn=a.tcp.ackn;else{var b=a.tcp.ackn-this.last_received_ackn;if(0<b){if(this.last_received_ackn=a.tcp.ackn,this.send_buffer.remove(b),this.seq+=b,this.pending=!1,this.delayed_send_fin&&!this.send_buffer.length){this.delayed_send_fin=!1;this.state=this.delayed_state;a=this.ipv4_reply();a.tcp.fin=!0;this.net.receive(Eb(this.net.eth_encoder_buf,a));return}}else if(0>b){a=this.packet_reply(a,{rst:!0});
188
- this.net.receive(Eb(this.net.eth_encoder_buf,a));this.on_close();this.release();return}}a.tcp.fin?(++this.ack,b=this.packet_reply(a,{}),"established"===this.state?(b.tcp.ack=!0,this.state="close-wait",this.on_shutdown()):"fin-wait-1"===this.state?(a.tcp.ack?this.release():this.state="closing",b.tcp.ack=!0):"fin-wait-2"===this.state?(this.release(),b.tcp.ack=!0):(this.release(),this.on_close(),b.tcp.rst=!0),this.net.receive(Eb(this.net.eth_encoder_buf,b))):this.ack!==a.tcp.seq?(a=this.packet_reply(a,
189
- {ack:!0}),this.net.receive(Eb(this.net.eth_encoder_buf,a))):a.tcp.ack&&0<a.tcp_data.length&&(this.ack+=a.tcp_data.length,b=this.ipv4_reply(),this.net.receive(Eb(this.net.eth_encoder_buf,b)),this.emit("data",a.tcp_data));this.pump()}};Jb.prototype.write=function(a){this.in_active_close||this.send_buffer.write(a);this.pump()};Jb.prototype.writev=function(a){if(!this.in_active_close)for(const b of a)this.send_buffer.write(b);this.pump()};Jb.prototype.close=function(){if(!this.in_active_close){this.in_active_close=
175
+ y(d);if(c.ipv4)if(c.tcp)a:{a=`${c.ipv4.src.join(".")}:${c.tcp.sport}:${c.ipv4.dest.join(".")}:${c.tcp.dport}`;if(c.tcp.syn&&!c.tcp.ack){b.tcp_conn[a]&&delete b.tcp_conn[a];d=new Jb(b);d.state="syn-received";d.tuple=a;d.last=c;d.hsrc=new Uint8Array(c.eth.dest);d.psrc=new Uint8Array(c.ipv4.dest);d.sport=c.tcp.dport;d.hdest=new Uint8Array(c.eth.src);d.dport=c.tcp.sport;d.pdest=new Uint8Array(c.ipv4.src);b.bus.pair.send("tcp-connection",d);if(b.on_tcp_connection)b.on_tcp_connection(d,c);if(b.tcp_conn[a])break a}if(b.tcp_conn[a])b.tcp_conn[a].process(c);
176
+ else{a=c.tcp.ackn;if(c.tcp.fin||c.tcp.syn)a+=1;d={};d.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src};d.ipv4={proto:6,src:c.ipv4.dest,dest:c.ipv4.src};d.tcp={sport:c.tcp.dport,dport:c.tcp.sport,seq:a,ackn:c.tcp.seq+(c.tcp.syn?1:0),winsize:c.tcp.winsize,rst:!0,ack:c.tcp.syn};b.receive(Eb(b.eth_encoder_buf,d))}}else if(c.udp)if(c.dns)if("static"===b.dns_method){a={};a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src};a.ipv4={proto:17,src:b.router_ip,dest:c.ipv4.src};a.udp={sport:53,dport:c.udp.sport};
177
+ d=[];for(e=0;e<c.dns.questions.length;++e)switch(l=c.dns.questions[e],l.type){case 1:d.push({name:l.name,type:l.type,class:l.class,ttl:600,data:[192,168,87,1]})}a.dns={id:c.dns.id,flags:33152,questions:c.dns.questions,answers:d};b.receive(Eb(b.eth_encoder_buf,a))}else Fb(c,b);else c.dhcp?Gb(c,b):c.ntp?(a=Date.now()+rb,d=a%1E3/1E3*wb,e={},e.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},e.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},e.udp={sport:123,dport:c.udp.sport},e.ntp=Object.assign({},
178
+ c.ntp),e.ntp.flags=36,e.ntp.poll=10,e.ntp.ori_ts_i=c.ntp.trans_ts_i,e.ntp.ori_ts_f=c.ntp.trans_ts_f,e.ntp.rec_ts_i=a/1E3,e.ntp.rec_ts_f=d,e.ntp.trans_ts_i=a/1E3,e.ntp.trans_ts_f=d,e.ntp.stratum=2,b.receive(Eb(b.eth_encoder_buf,e))):8===c.udp.dport&&(a={},a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},a.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},a.udp={sport:c.udp.dport,dport:c.udp.sport,data:(new TextEncoder).encode(c.udp.data_s)},b.receive(Eb(b.eth_encoder_buf,a)));else c.icmp&&8===
179
+ c.icmp.type&&(a={},a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},a.ipv4={proto:1,src:c.ipv4.dest,dest:c.ipv4.src},a.icmp={type:0,code:c.icmp.code,data:c.icmp.data},b.receive(Eb(b.eth_encoder_buf,a)));else c.arp&&1===c.arp.oper&&2048===c.arp.ptype&&(a=zb(c.arp.tpa)&4294967040,d=zb(b.router_ip)&4294967040,!b.masquerade&&a!==d||a===d&&99<c.arp.tpa[3]||(a={},a.eth={ethertype:2054,src:b.router_mac,dest:c.eth.src},a.arp={htype:1,ptype:2048,oper:2,sha:b.router_mac,spa:c.arp.tpa,tha:c.eth.src,tpa:c.arp.spa},
180
+ b.receive(Eb(b.eth_encoder_buf,a))))}function Ib(a,b){function c(){let m=[],n;do n=d.getUint8(h),m.push((new TextDecoder).decode(a.subarray(h+1,h+1+n))),h+=n+1;while(0<n);return m}let d=new DataView(a.buffer,a.byteOffset,a.byteLength),e={id:d.getUint16(0),flags:d.getUint16(2),questions:[],answers:[]};var f=d.getUint16(4);let g=d.getUint16(6);d.getUint16(8);d.getUint16(10);let h=12;for(var l=0;l<f;l++)e.questions.push({name:c(),type:d.getInt16(h),class:d.getInt16(h+2)}),h+=4;for(f=0;f<g;f++){l={name:c(),
181
+ type:d.getInt16(h),class:d.getUint16(h+2),ttl:d.getUint32(h+4)};h+=8;let m=d.getUint16(h);h+=2;l.data=a.subarray(h,h+m);h+=m;e.answers.push(l)}b.dns=e}function Tb(a,b){var c=b.vm_ip.join(".");const d=b.router_ip.join("."),e=16383*Math.random()|0;let f,g,h=0;do f=49152+(e+h)%16383,g=`${c}:${a}:${d}:${f}`;while(16383>++h&&b.tcp_conn[g]);if(b.tcp_conn[g])throw Error("pool of dynamic TCP port numbers exhausted, connection aborted");c=new Jb(b);c.tuple=g;c.hsrc=b.router_mac;c.psrc=b.router_ip;c.sport=
182
+ f;c.hdest=b.vm_mac;c.dport=a;c.pdest=b.vm_ip;b.tcp_conn[g]=c;c.connect();return c}function Ub(a,b){return new Promise(c=>{let d=Tb(a,b);d.state="syn-probe";d.on("probe",c)})}function Jb(a){this.mtu=a.mtu||1500;const b=this.mtu-20-20;this.state="closed";this.net=a;this.send_buffer=new Ab(2048,0);this.send_chunk_buf=new Uint8Array(b);this.delayed_send_fin=this.in_active_close=!1;this.delayed_state=void 0;this.events_handlers={}}Jb.prototype.on=function(a,b){this.events_handlers[a]=b};Jb.prototype.emit=
183
+ function(a,...b){this.events_handlers[a]&&this.events_handlers[a].apply(this,b)};Jb.prototype.ipv4_reply=function(){let a={};a.eth={ethertype:2048,src:this.hsrc,dest:this.hdest};a.ipv4={proto:6,src:this.psrc,dest:this.pdest};a.tcp={sport:this.sport,dport:this.dport,winsize:this.winsize,ackn:this.ack,seq:this.seq,ack:!0};return a};Jb.prototype.packet_reply=function(a,b){a={sport:a.tcp.dport,dport:a.tcp.sport,winsize:a.tcp.winsize,ackn:this.ack,seq:this.seq};if(b)for(const c in b)a[c]=b[c];b=this.ipv4_reply();
184
+ b.tcp=a;return b};Jb.prototype.connect=function(){this.seq=1338;this.ack=1;this.start_seq=0;this.winsize=64240;"syn-probe"!==this.state&&(this.state="syn-sent");let a=this.ipv4_reply();a.ipv4.id=2345;a.tcp={sport:this.sport,dport:this.dport,seq:1337,ackn:0,winsize:0,syn:!0};this.net.receive(Eb(this.net.eth_encoder_buf,a))};Jb.prototype.accept=function(a){a=a||this.last;this.net.tcp_conn[this.tuple]=this;this.seq=1338;this.ack=a.tcp.seq+1;this.start_seq=a.tcp.seq;this.winsize=a.tcp.winsize;let b=this.ipv4_reply();
185
+ b.tcp={sport:this.sport,dport:this.dport,seq:1337,ackn:this.ack,winsize:a.tcp.winsize,syn:!0,ack:!0,options:{mss:this.mtu-20-20}};this.state="established";this.net.receive(Eb(this.net.eth_encoder_buf,b))};Jb.prototype.process=function(a){this.last=a;if("closed"===this.state)a=this.packet_reply(a,{rst:!0}),this.net.receive(Eb(this.net.eth_encoder_buf,a));else if(a.tcp.rst){if("syn-probe"===this.state)this.emit("probe",!1);else this.on_close();this.release()}else if(a.tcp.syn)"syn-sent"===this.state&&
186
+ a.tcp.ack?(this.ack=a.tcp.seq+1,this.start_seq=a.tcp.seq,this.last_received_ackn=a.tcp.ackn,a=this.ipv4_reply(),this.net.receive(Eb(this.net.eth_encoder_buf,a)),this.state="established",this.emit("connect")):"syn-probe"===this.state&&a.tcp.ack&&(this.emit("probe",!0),a=this.packet_reply(a,{rst:!0}),this.net.receive(Eb(this.net.eth_encoder_buf,a)),this.release());else{if(a.tcp.ack)if("syn-received"===this.state)this.state="established";else if("fin-wait-1"===this.state)a.tcp.fin||(this.state="fin-wait-2");
187
+ else if("closing"===this.state||"last-ack"===this.state){this.release();return}if(void 0===this.last_received_ackn)this.last_received_ackn=a.tcp.ackn;else{var b=a.tcp.ackn-this.last_received_ackn;if(0<b){if(this.last_received_ackn=a.tcp.ackn,this.send_buffer.remove(b),this.seq+=b,this.pending=!1,this.delayed_send_fin&&!this.send_buffer.length){this.delayed_send_fin=!1;this.state=this.delayed_state;a=this.ipv4_reply();a.tcp.fin=!0;this.net.receive(Eb(this.net.eth_encoder_buf,a));return}}else if(0>
188
+ b){a=this.packet_reply(a,{rst:!0});this.net.receive(Eb(this.net.eth_encoder_buf,a));this.on_close();this.release();return}}a.tcp.fin?(++this.ack,b=this.packet_reply(a,{}),"established"===this.state?(b.tcp.ack=!0,this.state="close-wait",this.on_shutdown()):"fin-wait-1"===this.state?(a.tcp.ack?this.release():this.state="closing",b.tcp.ack=!0):"fin-wait-2"===this.state?(this.release(),b.tcp.ack=!0):(this.release(),this.on_close(),b.tcp.rst=!0),this.net.receive(Eb(this.net.eth_encoder_buf,b))):this.ack!==
189
+ a.tcp.seq?(a=this.packet_reply(a,{ack:!0}),this.net.receive(Eb(this.net.eth_encoder_buf,a))):a.tcp.ack&&0<a.tcp_data.length&&(this.ack+=a.tcp_data.length,b=this.ipv4_reply(),this.net.receive(Eb(this.net.eth_encoder_buf,b)),this.emit("data",a.tcp_data));this.pump()}};Jb.prototype.write=function(a){this.in_active_close||this.send_buffer.write(a);this.pump()};Jb.prototype.writev=function(a){if(!this.in_active_close)for(const b of a)this.send_buffer.write(b);this.pump()};Jb.prototype.close=function(){if(!this.in_active_close){this.in_active_close=
190
190
  !0;if("established"===this.state||"syn-received"===this.state)var a="fin-wait-1";else if("close-wait"===this.state)a="last-ack";else{this.release();return}this.send_buffer.length||this.pending?(this.delayed_send_fin=!0,this.delayed_state=a):(this.state=a,a=this.ipv4_reply(),a.tcp.fin=!0,this.net.receive(Eb(this.net.eth_encoder_buf,a)))}this.pump()};Jb.prototype.on_shutdown=function(){this.emit("shutdown")};Jb.prototype.on_close=function(){this.emit("close")};Jb.prototype.release=function(){this.net.tcp_conn[this.tuple]&&
191
191
  (this.state="closed",delete this.net.tcp_conn[this.tuple])};Jb.prototype.pump=function(){if(this.send_buffer.length&&!this.pending){const a=this.send_chunk_buf,b=this.send_buffer.peek(a),c=this.ipv4_reply();c.tcp.psh=!0;c.tcp_data=a.subarray(0,b);this.net.receive(Eb(this.net.eth_encoder_buf,c));this.pending=!0}};function Vb(a,b){b=b||{};this.bus=a;this.id=b.id||0;this.router_mac=new Uint8Array((b.router_mac||"52:54:0:1:2:3").split(":").map(function(c){return parseInt(c,16)}));this.router_ip=new Uint8Array((b.router_ip||
192
192
  "192.168.86.1").split(".").map(function(c){return parseInt(c,10)}));this.vm_ip=new Uint8Array((b.vm_ip||"192.168.86.100").split(".").map(function(c){return parseInt(c,10)}));this.masquerade=void 0===b.masquerade||!!b.masquerade;this.vm_mac=new Uint8Array(6);this.dns_method=b.dns_method||"static";this.doh_server=b.doh_server;this.tcp_conn={};this.mtu=b.mtu;this.eth_encoder_buf=Bb(this.mtu);this.fetch=(...c)=>fetch(...c);this.cors_proxy=b.cors_proxy;this.bus.register("net"+this.id+"-mac",function(c){this.vm_mac=
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "v86",
3
- "version": "0.5.325+g7b68d4b",
3
+ "version": "0.5.326+gd6368e3",
4
4
  "license": "BSD-2-Clause",
5
5
  "description": "x86 PC emulator and x86-to-wasm JIT, running in the browser",
6
6
  "homepage": "https://copy.sh/v86/",