v86 icon indicating copy to clipboard operation
v86 copied to clipboard

Use networking without the websocket proxy?

Open BelleNottelling opened this issue 6 years ago • 27 comments

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)

BelleNottelling avatar Mar 13 '18 04:03 BelleNottelling

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.

copy avatar Mar 13 '18 22:03 copy

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

BelleNottelling avatar Mar 15 '18 00:03 BelleNottelling

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:

  • 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
  • allow the VM to wget or curl things from your origin (e.g., leave large, optional pieces of the vm's files) on the origin server, but let the browser fetch them and feed the ArrayBuffers into the vm.
  • Allow something more robust than xterm->ttyS0 so you can easily manage window resizing. I'd love to connect my xterm.js session to a network interface and have this happen automatically.

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?

humphd avatar Jun 13 '18 15:06 humphd

@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?

dawnofman avatar Mar 31 '21 09:03 dawnofman

@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

BelleNottelling avatar Apr 02 '21 23:04 BelleNottelling

@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?

dawnofman avatar Apr 14 '21 11:04 dawnofman

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

proxy-m avatar Dec 28 '21 11:12 proxy-m

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 avatar Jul 12 '22 01:07 hello-smile6

# 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.

hello-smile6 avatar Jul 12 '22 01:07 hello-smile6

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

proxy-m avatar Jul 14 '22 20:07 proxy-m

@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 avatar Jul 14 '22 20:07 hello-smile6

@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.

hello-smile6 avatar Jul 14 '22 20:07 hello-smile6

@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?

burggraf avatar Sep 10 '22 17:09 burggraf

@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.

hello-smile6 avatar Sep 11 '22 00:09 hello-smile6

Now I'm getting this: image

burggraf avatar Sep 11 '22 12:09 burggraf

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 avatar Sep 12 '22 07:09 hello-smile6

Now I'm getting this: image

Replit fixed it, works now!

hello-smile6 avatar Oct 12 '22 04:10 hello-smile6

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!

SugarRayLua avatar Nov 07 '22 00:11 SugarRayLua

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?

ppacory avatar Nov 14 '22 21:11 ppacory

Can you share your code for this?

burggraf avatar Nov 14 '22 21:11 burggraf

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/)

ppacory avatar Nov 14 '22 21:11 ppacory

Let us know if that performs better. Thanks!

burggraf avatar Nov 14 '22 21:11 burggraf

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

copy avatar Nov 16 '22 17:11 copy

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

farhan-ct avatar Jan 23 '24 07:01 farhan-ct

@farhan-ct

to access the repo

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

proxy-m avatar Jan 25 '24 09:01 proxy-m

Thank you @proxy-m

farhan-ct avatar Jan 29 '24 02:01 farhan-ct

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)

SuperMaxusa avatar Mar 05 '24 07:03 SuperMaxusa