@@ -23,14 +23,7 @@ import (
23
23
identify "github.com/libp2p/go-libp2p/p2p/protocol/identify"
24
24
)
25
25
26
- const offlineIdErrorMessage = `'ipfs id' currently cannot query information on remote
27
- peers without a running daemon; we are working to fix this.
28
- In the meantime, if you want to query remote peers using 'ipfs id',
29
- please run the daemon:
30
-
31
- ipfs daemon &
32
- ipfs id QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ
33
- `
26
+ const offlineIdErrorMessage = "'ipfs id' cannot query information on remote peers without a running daemon; use the --offline option instead."
34
27
35
28
type IdOutput struct {
36
29
ID string
@@ -102,19 +95,21 @@ EXAMPLE:
102
95
return cmds .EmitOnce (res , output )
103
96
}
104
97
105
- // TODO handle offline mode with polymorphism instead of conditionals
106
- if ! n .IsOnline {
98
+ offline , _ := req . Options [ OfflineOption ].( bool )
99
+ if ! offline && ! n .IsOnline {
107
100
return errors .New (offlineIdErrorMessage )
108
101
}
109
102
110
- // We need to actually connect to run identify.
111
- err = n .PeerHost .Connect (req .Context , peer.AddrInfo {ID : id })
112
- switch err {
113
- case nil :
114
- case kb .ErrLookupFailure :
115
- return errors .New (offlineIdErrorMessage )
116
- default :
117
- return err
103
+ if ! offline {
104
+ // We need to actually connect to run identify.
105
+ err = n .PeerHost .Connect (req .Context , peer.AddrInfo {ID : id })
106
+ switch err {
107
+ case nil :
108
+ case kb .ErrLookupFailure :
109
+ return errors .New (offlineIdErrorMessage )
110
+ default :
111
+ return err
112
+ }
118
113
}
119
114
120
115
output , err := printPeer (keyEnc , n .Peerstore , id )
0 commit comments