diff --git a/ant.go b/ant.go index 4073b85..ee1c624 100644 --- a/ant.go +++ b/ant.go @@ -34,7 +34,6 @@ type AntConfig struct { PrivateKey crypto.PrivKey UserAgent string Port int - PortWSS int ProtocolPrefix string BootstrapPeers []peer.AddrInfo EventsChan chan ants.RequestEvent @@ -105,12 +104,12 @@ func SpawnAnt(ctx context.Context, ps peerstore.Peerstore, ds ds.Batching, cfg * fmt.Sprintf("/ip4/0.0.0.0/udp/%d/quic-v1", cfg.Port), fmt.Sprintf("/ip4/0.0.0.0/udp/%d/quic-v1/webtransport", cfg.Port), fmt.Sprintf("/ip4/0.0.0.0/udp/%d/webrtc-direct", cfg.Port), - fmt.Sprintf("/ip4/0.0.0.0/tcp/%d/tls/sni/*.%s/ws", cfg.PortWSS, forgeDomain), // cert manager websocket multi address + fmt.Sprintf("/ip4/0.0.0.0/tcp/%d/tls/sni/*.%s/ws", cfg.Port, forgeDomain), // cert manager websocket multi address fmt.Sprintf("/ip6/::/tcp/%d", cfg.Port), fmt.Sprintf("/ip6/::/udp/%d/quic-v1", cfg.Port), fmt.Sprintf("/ip6/::/udp/%d/quic-v1/webtransport", cfg.Port), fmt.Sprintf("/ip6/::/udp/%d/webrtc-direct", cfg.Port), - fmt.Sprintf("/ip6/::/tcp/%d/tls/sni/*.%s/ws", cfg.PortWSS, forgeDomain), // cert manager websocket multi address + fmt.Sprintf("/ip6/::/tcp/%d/tls/sni/*.%s/ws", cfg.Port, forgeDomain), // cert manager websocket multi address } opts := []libp2p.Option{ @@ -120,6 +119,7 @@ func SpawnAnt(ctx context.Context, ps peerstore.Peerstore, ds ds.Batching, cfg * libp2p.DisableRelay(), libp2p.ListenAddrStrings(listenAddrs...), libp2p.DisableMetrics(), + libp2p.ShareTCPListener(), libp2p.Transport(libp2ptcp.NewTCPTransport), libp2p.Transport(libp2pquic.NewTransport), libp2p.Transport(libp2pwebtransport.New), @@ -188,7 +188,7 @@ func SpawnAnt(ctx context.Context, ps peerstore.Peerstore, ds ds.Batching, cfg * default: continue } - logger.Infof(" [%d] %s %s", i, actionStr, maddr.Address) + logger.Infof(" [%d] %s %s/p2p/%s", i, actionStr, maddr.Address, h.ID()) } case event.EvtLocalReachabilityChanged: logger.Infow("Reachability changed", "ant", h.ID(), "reachability", evt.Reachability) diff --git a/cmd/ants/main.go b/cmd/ants/main.go index 9005dcf..c0fe801 100644 --- a/cmd/ants/main.go +++ b/cmd/ants/main.go @@ -31,7 +31,6 @@ var queenConfig = struct { KeyDBPath string NumPorts int FirstPort int - FirstPortWSS int UPnp bool BatchSize int BatchTime time.Duration @@ -61,7 +60,6 @@ var queenConfig = struct { BucketSize: 20, UserAgent: "celestiant", QueenID: "", - FirstPortWSS: 7000, } func main() { @@ -175,13 +173,6 @@ func main() { Destination: &queenConfig.FirstPort, Value: queenConfig.FirstPort, }, - &cli.IntFlag{ - Name: "first_port_wss", - Usage: "First port ants can listen on for secure websockets", - EnvVars: []string{"ANTS_FIRST_PORT_WSS"}, - Destination: &queenConfig.FirstPortWSS, - Value: queenConfig.FirstPortWSS, - }, &cli.IntFlag{ Name: "num_ports", Usage: "Number of ports ants can listen on", @@ -306,7 +297,6 @@ func runQueenCommand(c *cli.Context) error { KeysDBPath: queenConfig.KeyDBPath, NPorts: queenConfig.NumPorts, FirstPort: queenConfig.FirstPort, - FirstPortWSS: queenConfig.FirstPortWSS, UPnP: queenConfig.UPnp, BatchSize: queenConfig.BatchSize, BatchTime: queenConfig.BatchTime, diff --git a/queen.go b/queen.go index 76947e2..284bccb 100644 --- a/queen.go +++ b/queen.go @@ -36,7 +36,6 @@ type QueenConfig struct { KeysDBPath string NPorts int FirstPort int - FirstPortWSS int UPnP bool BatchSize int BatchTime time.Duration @@ -48,10 +47,6 @@ type QueenConfig struct { Telemetry *metrics.Telemetry } -func (cfg *QueenConfig) RangesOverlap() bool { - return cfg.FirstPort+cfg.NPorts > cfg.FirstPortWSS && cfg.FirstPort < cfg.FirstPortWSS+cfg.NPorts -} - type Queen struct { cfg *QueenConfig @@ -76,10 +71,6 @@ type Queen struct { } func NewQueen(clickhouseClient db.Client, cfg *QueenConfig) (*Queen, error) { - if cfg.RangesOverlap() { - return nil, fmt.Errorf("port ranges overlap") - } - ps, err := pstoremem.NewPeerstore() if err != nil { return nil, fmt.Errorf("creating peerstore: %w", err) @@ -118,9 +109,9 @@ func NewQueen(clickhouseClient db.Client, cfg *QueenConfig) (*Queen, error) { return queen, nil } -func (q *Queen) takeAvailablePort() (int, int, error) { +func (q *Queen) takeAvailablePort() (int, error) { if q.cfg.UPnP { - return 0, 0, nil + return 0, nil } for i, occupied := range q.portsOccupancy { @@ -128,10 +119,10 @@ func (q *Queen) takeAvailablePort() (int, int, error) { continue } q.portsOccupancy[i] = true - return q.cfg.FirstPort + i, q.cfg.FirstPortWSS + i, nil + return q.cfg.FirstPort + i, nil } - return 0, 0, fmt.Errorf("no available port") + return 0, fmt.Errorf("no available port") } func (q *Queen) freePort(port int) { @@ -293,6 +284,7 @@ func (q *Queen) routine(ctx context.Context) { // zones correspond to the prefixes of the tries that must be covered by an ant zones := trieZones(networkTrie, q.cfg.BucketSize) + zones = zones[0:1] logger.Debugf("%d zones must be covered by ants", len(zones)) // convert string zone to bitstr.Key @@ -341,7 +333,7 @@ func (q *Queen) routine(ctx context.Context) { // add missing ants privKeys := q.keysDB.MatchingKeys(missingKeys, returnedKeys) for _, key := range privKeys { - port, portWSS, err := q.takeAvailablePort() + port, err := q.takeAvailablePort() if err != nil { logger.Error("trying to spawn new ant: ", err) continue @@ -351,7 +343,6 @@ func (q *Queen) routine(ctx context.Context) { PrivateKey: key, UserAgent: q.cfg.UserAgent, Port: port, - PortWSS: portWSS, ProtocolPrefix: fmt.Sprintf("/celestia/%s", celestiaNet), // TODO: parameterize BootstrapPeers: BootstrapPeers(celestiaNet), // TODO: parameterize EventsChan: q.antsEvents,