mirror of
				https://github.com/yggdrasil-network/yggstack.git
				synced 2025-11-04 00:15:06 +03:00 
			
		
		
		
	Implemented UNIX socket support for SOCKS5 server in yggstack command and updated README.md with usage instructions.
This commit is contained in:
		
							parent
							
								
									edbaa72445
								
							
						
					
					
						commit
						23d4321be4
					
				
					 2 changed files with 54 additions and 14 deletions
				
			
		| 
						 | 
					@ -78,6 +78,12 @@ To run SOCKS proxy server listening on local port 1080 using generated configura
 | 
				
			||||||
./yggstack -useconffile /path/to/yggdrasil.conf -socks 127.0.0.1:1080
 | 
					./yggstack -useconffile /path/to/yggdrasil.conf -socks 127.0.0.1:1080
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					To run SOCKS proxy server listening on UNIX socket file `/tmp/yggstack.sock`:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					./yggstack -useconffile /path/to/yggdrasil.conf -socks /tmp/yggstack.sock
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
To expose network services (like a Web server) listening on local port 8080 to Yggdrasil
 | 
					To expose network services (like a Web server) listening on local port 8080 to Yggdrasil
 | 
				
			||||||
network address at port 80:
 | 
					network address at port 80:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,7 @@ import (
 | 
				
			||||||
	"crypto/ed25519"
 | 
						"crypto/ed25519"
 | 
				
			||||||
	"encoding/hex"
 | 
						"encoding/hex"
 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
	"flag"
 | 
						"flag"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"net"
 | 
						"net"
 | 
				
			||||||
| 
						 | 
					@ -34,6 +35,7 @@ type node struct {
 | 
				
			||||||
	core           *core.Core
 | 
						core           *core.Core
 | 
				
			||||||
	multicast      *multicast.Multicast
 | 
						multicast      *multicast.Multicast
 | 
				
			||||||
	admin          *admin.AdminSocket
 | 
						admin          *admin.AdminSocket
 | 
				
			||||||
 | 
						socks5Listener net.Listener
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// The main function is responsible for configuring and starting Yggdrasil.
 | 
					// The main function is responsible for configuring and starting Yggdrasil.
 | 
				
			||||||
| 
						 | 
					@ -52,7 +54,7 @@ func main() {
 | 
				
			||||||
	getsnet := flag.Bool("subnet", false, "use in combination with either -useconf or -useconffile, outputs your IPv6 subnet")
 | 
						getsnet := flag.Bool("subnet", false, "use in combination with either -useconf or -useconffile, outputs your IPv6 subnet")
 | 
				
			||||||
	getpkey := flag.Bool("publickey", false, "use in combination with either -useconf or -useconffile, outputs your public key")
 | 
						getpkey := flag.Bool("publickey", false, "use in combination with either -useconf or -useconffile, outputs your public key")
 | 
				
			||||||
	loglevel := flag.String("loglevel", "info", "loglevel to enable")
 | 
						loglevel := flag.String("loglevel", "info", "loglevel to enable")
 | 
				
			||||||
	socks := flag.String("socks", "", "address to listen on for SOCKS, i.e. :1080")
 | 
						socks := flag.String("socks", "", "address to listen on for SOCKS, i.e. :1080; or UNIX socket file path, i.e. /tmp/yggstack.sock")
 | 
				
			||||||
	nameserver := flag.String("nameserver", "", "the Yggdrasil IPv6 address to use as a DNS server for SOCKS")
 | 
						nameserver := flag.String("nameserver", "", "the Yggdrasil IPv6 address to use as a DNS server for SOCKS")
 | 
				
			||||||
	flag.Var(&expose, "exposetcp", "TCP ports to expose to the network, e.g. 22, 2022:22, 22:192.168.1.1:2022")
 | 
						flag.Var(&expose, "exposetcp", "TCP ports to expose to the network, e.g. 22, 2022:22, 22:192.168.1.1:2022")
 | 
				
			||||||
	flag.Parse()
 | 
						flag.Parse()
 | 
				
			||||||
| 
						 | 
					@ -271,7 +273,10 @@ func main() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Create SOCKS server
 | 
						// Create SOCKS server
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if socks != nil && nameserver != nil && *socks != "" {
 | 
							if socks != nil {
 | 
				
			||||||
 | 
								if nameserver != nil {
 | 
				
			||||||
 | 
									if strings.Contains(*socks, ":") {
 | 
				
			||||||
 | 
										logger.Infof("Starting SOCKS server on %s", *socks)
 | 
				
			||||||
					resolver := types.NewNameResolver(s, *nameserver)
 | 
										resolver := types.NewNameResolver(s, *nameserver)
 | 
				
			||||||
					socksOptions := []socks5.Option{
 | 
										socksOptions := []socks5.Option{
 | 
				
			||||||
						socks5.WithDial(s.DialContext),
 | 
											socks5.WithDial(s.DialContext),
 | 
				
			||||||
| 
						 | 
					@ -282,6 +287,31 @@ func main() {
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					server := socks5.NewServer(socksOptions...)
 | 
										server := socks5.NewServer(socksOptions...)
 | 
				
			||||||
					go server.ListenAndServe("tcp", *socks) // nolint:errcheck
 | 
										go server.ListenAndServe("tcp", *socks) // nolint:errcheck
 | 
				
			||||||
 | 
									} else {
 | 
				
			||||||
 | 
										logger.Infof("Starting SOCKS server with socket file %s", *socks)
 | 
				
			||||||
 | 
										_, err := os.Stat(*socks)
 | 
				
			||||||
 | 
										if os.IsNotExist(err) {
 | 
				
			||||||
 | 
											n.socks5Listener, err = net.Listen("unix", *socks)
 | 
				
			||||||
 | 
											if err != nil {
 | 
				
			||||||
 | 
												panic(err)
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											resolver := types.NewNameResolver(s, *nameserver)
 | 
				
			||||||
 | 
											socksOptions := []socks5.Option{
 | 
				
			||||||
 | 
												socks5.WithDial(s.DialContext),
 | 
				
			||||||
 | 
												socks5.WithResolver(resolver),
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											if logger.GetLevel("debug") {
 | 
				
			||||||
 | 
												socksOptions = append(socksOptions, socks5.WithLogger(logger))
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											server := socks5.NewServer(socksOptions...)
 | 
				
			||||||
 | 
											go server.Serve(n.socks5Listener) // nolint:errcheck
 | 
				
			||||||
 | 
										} else if err != nil {
 | 
				
			||||||
 | 
											logger.Errorf("Cannot create socket file %s: %s", *socks, err)
 | 
				
			||||||
 | 
										} else {
 | 
				
			||||||
 | 
											panic(errors.New(fmt.Sprintf("Socket file %s already exists", *socks)))
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -317,6 +347,10 @@ func main() {
 | 
				
			||||||
	// Shut down the node.
 | 
						// Shut down the node.
 | 
				
			||||||
	_ = n.admin.Stop()
 | 
						_ = n.admin.Stop()
 | 
				
			||||||
	_ = n.multicast.Stop()
 | 
						_ = n.multicast.Stop()
 | 
				
			||||||
 | 
						if n.socks5Listener != nil {
 | 
				
			||||||
 | 
							_ = n.socks5Listener.Close()
 | 
				
			||||||
 | 
							logger.Infof("Stopped UNIX socket listener")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	n.core.Stop()
 | 
						n.core.Stop()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue