Skip to content

Commit

Permalink
Merge pull request #11294 from filecoin-project/phi-connect-listen-no…
Browse files Browse the repository at this point in the history
…t-set

fix: worker: Connect when --listen is not set
  • Loading branch information
magik6k authored Sep 25, 2023
2 parents 121cd97 + f1c7072 commit d64bc2c
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions cmd/lotus-worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ var runCmd = &cli.Command{
Storage: lr,
}

log.Info("Setting up control endpoint at " + address)
log.Info("Setting up control endpoint at " + newAddress)

timeout, err := time.ParseDuration(cctx.String("http-server-timeout"))
if err != nil {
Expand All @@ -652,13 +652,13 @@ var runCmd = &cli.Command{
log.Warn("Graceful shutdown successful")
}()

nl, err := net.Listen("tcp", address)
nl, err := net.Listen("tcp", newAddress)
if err != nil {
return err
}

{
a, err := net.ResolveTCPAddr("tcp", address)
a, err := net.ResolveTCPAddr("tcp", newAddress)
if err != nil {
return xerrors.Errorf("parsing address: %w", err)
}
Expand Down Expand Up @@ -739,7 +739,7 @@ var runCmd = &cli.Command{

select {
case <-readyCh:
if err := nodeApi.WorkerConnect(ctx, "http://"+address+"/rpc/v0"); err != nil {
if err := nodeApi.WorkerConnect(ctx, "http://"+newAddress+"/rpc/v0"); err != nil {
log.Errorf("Registering worker failed: %+v", err)
cancel()
return
Expand Down Expand Up @@ -801,15 +801,13 @@ func extractRoutableIP(timeout time.Duration) (string, error) {
}

minerIP, _ := maddr.ValueForProtocol(multiaddr.P_IP6)
if minerIP == "" {
minerIP, _ = maddr.ValueForProtocol(multiaddr.P_IP4)
}
minerPort, _ := maddr.ValueForProtocol(multiaddr.P_TCP)

// Check if the IP is IPv6 and format the address appropriately
var addressToDial string
if ip := net.ParseIP(minerIP); ip.To4() == nil && ip.To16() != nil {
addressToDial = "[" + minerIP + "]:" + minerPort
} else {
addressToDial = minerIP + ":" + minerPort
}
// Format the address appropriately
addressToDial := net.JoinHostPort(minerIP, minerPort)

conn, err := net.DialTimeout("tcp", addressToDial, timeout)
if err != nil {
Expand Down

0 comments on commit d64bc2c

Please sign in to comment.