Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ipfs swarm peering crash in offline mode #9261

Merged
merged 4 commits into from
Oct 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions core/commands/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ var swarmPeeringAddCmd = &cmds.Command{
if err != nil {
return err
}
if !node.IsOnline {
return ErrNotOnline
}

for _, addrinfo := range addInfos {
node.Peering.AddPeer(addrinfo)
Expand Down Expand Up @@ -153,6 +156,10 @@ var swarmPeeringLsCmd = &cmds.Command{
if err != nil {
return err
}
if !node.IsOnline {
return ErrNotOnline
}

peers := node.Peering.ListPeers()
return cmds.EmitOnce(res, addrInfos{Peers: peers})
},
Expand Down Expand Up @@ -189,6 +196,9 @@ var swarmPeeringRmCmd = &cmds.Command{
if err != nil {
return err
}
if !node.IsOnline {
return ErrNotOnline
}

for _, arg := range req.Arguments {
id, err := peer.Decode(arg)
Expand All @@ -206,7 +216,7 @@ var swarmPeeringRmCmd = &cmds.Command{
Type: peeringResult{},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, pr *peeringResult) error {
fmt.Fprintf(w, "add %s %s\n", pr.ID.String(), pr.Status)
fmt.Fprintf(w, "remove %s %s\n", pr.ID.String(), pr.Status)
return nil
}),
},
Expand Down Expand Up @@ -840,7 +850,7 @@ Filters default to those specified under the "Swarm.AddrFilters" config key.
return err
}

if n.PeerHost == nil {
if !n.IsOnline {
return ErrNotOnline
}

Expand Down Expand Up @@ -876,7 +886,7 @@ var swarmFiltersAddCmd = &cmds.Command{
return err
}

if n.PeerHost == nil {
if !n.IsOnline {
return ErrNotOnline
}

Expand Down Expand Up @@ -932,7 +942,7 @@ var swarmFiltersRmCmd = &cmds.Command{
return err
}

if n.PeerHost == nil {
if !n.IsOnline {
return ErrNotOnline
}

Expand Down