do init id offline, only dont parse keys
(test was failing)
Juan Batiz-Benet committed
Sep 30, 2014 at 03:31 UTC
c0546198272a207d7b6df136f4d86cf8075ec1c7
1 file changed
+24
-16
core/core.go
+24
-16
@@ -86,6 +86,11 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
86
87
peerstore := peer.NewPeerstore()
88
89
+ local, err := initIdentity(cfg, online)
90
+ if err != nil {
91
+ return nil, err
92
+ }
93
+
94
// FIXME(brian): This is a bit dangerous. If any of the vars declared in
95
// this block are assigned inside of the "if online" block using the ":="
96
// declaration syntax, the compiler permits re-declaration. This is rather
@@ -95,17 +100,10 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
100
// TODO: refactor so we can use IpfsRouting interface instead of being DHT-specific
101
route *dht.IpfsDHT
102
exchangeSession exchange.Interface
98
- local *peer.Peer
103
)
104
105
if online {
106
103
- // when not online, don't need to parse private keys (yet)
104
- local, err := initIdentity(cfg)
105
- if err != nil {
106
- return nil, err
107
- }
108
-
107
dhtService := netservice.NewService(nil) // nil handler for now, need to patch it
108
exchangeService := netservice.NewService(nil) // nil handler for now, need to patch it
109
@@ -159,7 +157,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
157
}, nil
158
}
159
162
-func initIdentity(cfg *config.Config) (*peer.Peer, error) {
160
+func initIdentity(cfg *config.Config, online bool) (*peer.Peer, error) {
161
if cfg.Identity.PeerID == "" {
162
return nil, errors.New("Identity was not set in config (was ipfs init run?)")
163
}
@@ -179,21 +177,31 @@ func initIdentity(cfg *config.Config) (*peer.Peer, error) {
177
addresses = []*ma.Multiaddr{maddr}
178
}
179
182
- skb, err := base64.StdEncoding.DecodeString(cfg.Identity.PrivKey)
183
- if err != nil {
184
- return nil, err
185
- }
180
+ var (
181
+ sk ci.PrivKey
182
+ pk ci.PubKey
183
+ )
184
187
- sk, err := ci.UnmarshalPrivateKey(skb)
188
- if err != nil {
189
- return nil, err
185
+ // when not online, don't need to parse private keys (yet)
186
+ if !online {
187
+ skb, err := base64.StdEncoding.DecodeString(cfg.Identity.PrivKey)
188
+ if err != nil {
189
+ return nil, err
190
+ }
191
+
192
+ sk, err = ci.UnmarshalPrivateKey(skb)
193
+ if err != nil {
194
+ return nil, err
195
+ }
196
+
197
+ pk = sk.GetPublic()
198
}
199
200
return &peer.Peer{
201
ID: peer.ID(b58.Decode(cfg.Identity.PeerID)),
202
Addresses: addresses,
203
PrivKey: sk,
196
- PubKey: sk.GetPublic(),
204
+ PubKey: pk,
205
}, nil
206
}
207