Merge pull request #32 from asmogo/remove_public_bind

remove PublicAddressBind
This commit is contained in:
asmogo 2024-08-04 14:37:14 +02:00 committed by GitHub
commit 1e12f602f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 7 deletions

View File

@ -15,7 +15,7 @@ Exit node [domain names](#nws-domain-names) make private services accessible to
### NWS main components ### NWS main components
1. **Exit node**: A TCP reverse proxy that listens for incoming Nostr subscriptions and forwards the payload to your designated backend service. 1. **Exit node**: A TCP reverse proxy that listens for incoming Nostr subscriptions and forwards the payload to your designated backend service.
2. **Entry node**: Forwards TCP packets to the exit node using a SOCKS proxy and creates encrypted events for the exit node. 2. **Entry node**: A SOCKS5 proxy that forwards TCP packets and creates encrypted events for the exit node.
<img src="nws.png" width="900"/> <img src="nws.png" width="900"/>
@ -117,5 +117,5 @@ If you don't want to use the `PUBLIC_ADDRESS` feature, no further configuration
PUBLIC_ADDRESS='<public_ip>:<port>' PUBLIC_ADDRESS='<public_ip>:<port>'
``` ```
- `PUBLIC_ADDRESS`: This can be set if the entry node is publicly available. When set, the entry node will additionally bind to this address. Exit node discovery will still be done using Nostr. Once a connection is established, this public address will be used to transmit further data. - `PUBLIC_ADDRESS`: This can be set if the entry node is publicly available. Exit node discovery will still be done using Nostr. Once a connection is established, this public address will be used to transmit further data. (`<ip/domain>:<port>`)
- `NOSTR_RELAYS`: A list of Nostr relays to publish events to. Used only if there is no relay data in the request. - `NOSTR_RELAYS`: A list of Nostr relays to publish events to. Used only if there is no relay data in the request.

View File

@ -10,9 +10,8 @@ import (
) )
type EntryConfig struct { type EntryConfig struct {
NostrRelays []string `env:"NOSTR_RELAYS" envSeparator:";"` NostrRelays []string `env:"NOSTR_RELAYS" envSeparator:";"`
PublicAddress string `env:"PUBLIC_ADDRESS"` PublicAddress string `env:"PUBLIC_ADDRESS"`
PublicAddressBind string `env:"PUBLIC_ADDRESS_BIND"`
} }
type ExitConfig struct { type ExitConfig struct {

View File

@ -99,9 +99,14 @@ func New(conf *Config, pool *nostr.SimplePool, config *config.EntryConfig) (*Ser
pool: pool, pool: pool,
} }
if conf.entryConfig.PublicAddress != "" { if conf.entryConfig.PublicAddress != "" {
listener, err := NewTCPListener(conf.entryConfig.PublicAddressBind) // parse host port
_, port, err := net.SplitHostPort(conf.entryConfig.PublicAddress)
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("failed to parse public address: %w", err)
}
listener, err := NewTCPListener(net.JoinHostPort(net.IP{0, 0, 0, 0}.String(), port))
if err != nil {
return nil, fmt.Errorf("failed to create tcp listener: %w", err)
} }
go listener.Start() go listener.Start()
server.tcpListener = listener server.tcpListener = listener
@ -114,6 +119,7 @@ func New(conf *Config, pool *nostr.SimplePool, config *config.EntryConfig) (*Ser
return server, nil return server, nil
} }
func (s *Server) Configuration() (*Config, error) { func (s *Server) Configuration() (*Config, error) {
if s.config != nil { if s.config != nil {
return s.config, nil return s.config, nil