copy / v86

x86 PC emulator and x86-to-wasm JIT, running in the browser
https://copy.sh/v86/
BSD 2-Clause "Simplified" License
19.65k stars 1.38k forks source link

Use networking without the websocket proxy? #198

Closed BelleNottelling closed 2 months ago

BelleNottelling commented 6 years ago

Currently, networking is run through https://github.com/benjamincburns/websockproxy which needs a server to be set up and have v86 pointed at it. It also limits the speed. I was wondering if we could run the networking through javascript calls instead or by some other local solution. (websockproxy also doesn't support https so it would be nice if there was a solution that could use that)

copy commented 6 years ago

There's not much we can do. One possibility would be to write a browser extension, but it's doubtful that this would be used by many people due to the security implications. Extension apis are also quite high-level (tcp/udp) I believe, so this would require an implementation of the full network stack below.

One could also implement proxies for the higher level protocols, for example an http and a dns proxy may be sufficient for most use-cases and don't need to be as restricted as the low-level proxy.

BelleNottelling commented 6 years ago

Alright.. well I guess I'll look around a little bit for this idea, but I'm not much of a developer

humphd commented 6 years ago

I've been thinking about this as well. Obviously full network (i.e., Internet) access is pretty much impossible due to browser origin/CORS/etc restrictions. However, I think LAN stye networking between the host, v86 vm, and original web server (i.e., your origin) could be really useful.

Here are some things that would be useful:

Re-implementing the entire network stack in JS to do all this seems like overkill. Could we not expose a higher-level network socket so these types of things are possible?

dawnofman commented 3 years ago

@BenNottelling Did you find any solution for this networking? I have a situation to stream data to a process running in the VM using network. Any suggestion?

BelleNottelling commented 3 years ago

@BenNottelling Did you find any solution for this networking? I have a situation to stream data to a process running in the VM using network. Any suggestion?

No, I never really looked into it. I just made my own proxy server without the rate limiting, but it's still quite slow. https://github.com/BenNottelling/websockproxy Also, it doesn't do HTTPS. I haven't looked into an improved solution

dawnofman commented 3 years ago

@humphd

* use a `postMessage` style interface to connect a JS "server" in the browser to something running in the VM
* similar to the above, but proxy a server running in the VM out to clients in the browser

I had setup an apache server inside the VM and trying to interface it to a webapp outside (may be imagine iframe) with postMessage. For instance, iframe.contenWindow.postMessage("message", "http://localhost");. It doesn't really work. Do you have an idea to expose webserver in the VM to outside?

proxy-m commented 2 years ago

Actually it is possible with WebRTC data channel. WebRTC requires signaling service and iceServers. Ice servers are optional for same computer and same network!

  1. Signaling service implementation is not a part of WebRTC standard, so it can be any and emulated with some stub/mock. Signaling (RTCPeerConnection.currentLocalDescription + RTCPeerConnection.currentRemoteDescription) is only required to start communication; then it can be ignored.

  2. ICE servers (multiple STUN and/or TURN) are optional. They are needed to resolve ip and url, when you are communicate between different networks or even with nat.

  3. WebRTC can transfer different things: video, audio or data (e.g. you can use only data).

  4. See also #569 #23 and №155

Examples of avoiding additional webrtc settings for data channel:

PeerJS - browser's WebRTC implementation to simplify peer-to-peer connection API WebRTC one to one without signaling server Simple Peer WebRTC Buggy data exchange example with php http signaling instead of websockets

hello-smile6 commented 2 years ago

Actually it is possible with WebRTC data channel. WebRTC requires signaling service and iceServers. Ice servers are optional for same computer and same network!

  1. Signaling service implementation is not a part of WebRTC standard, so it can be any and emulated with some stub/mock. Signaling (RTCPeerConnection.currentLocalDescription + RTCPeerConnection.currentRemoteDescription) is only required to start communication; then it can be ignored.
  2. ICE servers (multiple STUN and/or TURN) are optional. They are needed to resolve ip and url, when you are communicate between different networks or even with nat.
  3. WebRTC can transfer different things: video, audio or data (e.g. you can use only data).
  4. See also Networking between two or more instances #569 Network support #23 and №155

Examples of avoiding additional webrtc settings for data channel:

PeerJS - browser's WebRTC implementation to simplify peer-to-peer connection API WebRTC one to one without signaling server Simple Peer WebRTC Buggy data exchange example with php http signaling instead of websockets

You were right! Turns out it's easier than you'd think. :)

hello-smile6 commented 2 years ago
# Change the following lines if you want dnsmasq to serve SRV                   
# records.                                                                      
# You may add multiple srv-host lines.                                          
# The fields are <name>,<target>,<port>,<priority>,<weight>                     
# interface=eth0                                                                
bind-interfaces                                                                 
domain=v86.p2p                                                                  
dhcp-option=3,255.0.0.0                                                         
dhcp-option=6,10.5.0.1                                                          
dhcp-option=121,10.5.0.2/24,10.5.0.1                                            
dhcp-range=10.5.0.2,10.5.250.250,5m                                             
# A SRV record sending LDAP for the example.com domain to                       
# ldapserver.example.com port 289                                               
#srv-host=_ldap._tcp.example.com,ldapserver.example.com,389                     

# Two SRV records for LDAP, each with different priorities                      
#srv-host=_ldap._tcp.example.com,ldapserver.example.com,389,1                   
#srv-host=_ldap._tcp.example.com,ldapserver.example.com,389,2                   

# A SRV record indicating that there is no LDAP server for the domain           
# example.com                                                                   
#srv-host=_ldap._tcp.example.com                                                

# The following line shows how to make dnsmasq serve an arbitrary PTR           
- /etc/dnsmasq.conf 1/43 2%                                                     

That's my dnsmasq.conf for OpenWRT (I copied dnsmasq.conf to /tmp and used `mount --bind /tmp/dnsmasq.conf /etc/dnsmasq.conf). DHCP actually works, surprisingly.

proxy-m commented 2 years ago

@hello-smile6 Thanks for config. DHCP is not a problem. But how do you connect instances through WebRTC?

hello-smile6 commented 2 years ago

@hello-smile6 Thanks for config. DHCP is not a problem. But how do you connect instances through WebRTC?

I'll upload to a Gitea repo and send a link.

hello-smile6 commented 2 years ago

@proxy-m https://gitea.9pfs.repl.co/9pfs/v86-webrtc-network/src/branch/main/ Feel free to add to it if there's something that could be improved.

burggraf commented 2 years ago

@proxy-m https://gitea.9pfs.repl.co/9pfs/v86-webrtc-network/src/branch/main/ Feel free to add to it if there's something that could be improved.

This appears to be down now. Can you check on it or move it to Github?

hello-smile6 commented 2 years ago

@proxy-m https://gitea.9pfs.repl.co/9pfs/v86-webrtc-network/src/branch/main/ Feel free to add to it if there's something that could be improved.

This appears to be down now. Can you check on it or move it to Github?

If my Git server is down, it will usually come back up within a few minutes.

burggraf commented 2 years ago

Now I'm getting this: image

hello-smile6 commented 2 years ago

Now I'm getting this: image

Partially my fault, partially Replit's fault. It should work within 24 hours, if it isn't already

hello-smile6 commented 1 year ago

Now I'm getting this: image

Replit fixed it, works now!

SugarRayLua commented 1 year ago

Hello, @hello-smile6. Would you mind explaining how to use your WebRTC data channel to get faster internet transfer speeds using v86? I'm a novice linux user and using the Arch Linux distro on v86 and would like to know if it is possible and how to modify my Arch Linux installation on v86 to use your WebRTC data channel.

Thanks!

ppacory commented 1 year ago

with the implementation of webrtc and direct peer to peer communication with @ip i get max speeds of 500Kb/s. has anyone managed to get better scores and if so how?

burggraf commented 1 year ago

Can you share your code for this?

ppacory commented 1 year ago

Can you share your code for this?

I have implemented the code provided above :
https://gitea.9pfs.repl.co/9pfs/v86-webrtc-network/src/branch/main/bridge2ws.js
but I can't go over 500kb/s, I'll try to use https://peerjs.com/ for webRTC and not bugout (https://chr15m.github.io/bugout/)

burggraf commented 1 year ago

Let us know if that performs better. Thanks!

copy commented 1 year ago

Here is another option: https://leaningtech.com/webvm-virtual-machine-with-networking-via-tailscale/

farhan-ct commented 8 months ago

Hi, I am unable to access the repo at https://gitea.9pfs.repl.co/9pfs/v86-webrtc-network/src/branch/main/

proxy-m commented 8 months ago

@farhan-ct

to access the repo

https://github.com/proxy-m/v86-webrtc-network

farhan-ct commented 8 months ago

Thank you @proxy-m

SuperMaxusa commented 7 months ago

If someone insterested, container2wasm have network stack that works on Fetch API: https://github.com/ktock/container2wasm/blob/main/examples/networking/fetch/README.md, but CORS limits are still applied (HTTP(S)-only connections and required allowed CORS on webserver side)