Skip to content

Commit fd7992f

Browse files
committed
Identity management
Signed-off-by: Gustavo Sampaio <[email protected]>
1 parent 6ef4f8a commit fd7992f

File tree

14 files changed

+451
-190
lines changed

14 files changed

+451
-190
lines changed

crabfs.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
crabfsCrypto "github.com/runletapp/crabfs/crypto"
12+
"github.com/runletapp/crabfs/identity"
1213
"github.com/runletapp/crabfs/interfaces"
1314
"github.com/runletapp/crabfs/options"
1415

@@ -50,20 +51,13 @@ func New(opts ...options.Option) (interfaces.Core, error) {
5051
return nil, ErrInvalidBlockSize
5152
}
5253

53-
// var privateKey *libp2pCrypto.RsaPrivateKey
54-
// var err error
55-
// if settings.PrivateKey == nil {
56-
// privKey, _, err := libp2pCrypto.GenerateRSAKeyPair(2048, rand.Reader)
57-
// if err != nil {
58-
// return nil, err
59-
// }
60-
// privateKey = privKey.(*libp2pCrypto.RsaPrivateKey)
61-
// } else {
62-
// privateKey, err = ReadPrivateKey(settings.PrivateKey)
63-
// if err != nil {
64-
// return nil, err
65-
// }
66-
// }
54+
if settings.Identity == nil {
55+
var err error
56+
settings.Identity, err = identity.CreateIdentity()
57+
if err != nil {
58+
return nil, err
59+
}
60+
}
6761

6862
var rawDatastore ipfsDatastore.Datastore
6963
if settings.Root == "" {
@@ -273,3 +267,7 @@ func (fs *crabFS) PublishPublicKey(publicKey crabfsCrypto.PubKey) error {
273267

274268
return fs.host.PutPublicKey(publicKey)
275269
}
270+
271+
func (fs *crabFS) GetIdentity() identity.Identity {
272+
return fs.settings.Identity
273+
}

examples/relay/relay.go

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ package main
33
import (
44
"context"
55
"flag"
6+
"io/ioutil"
67
"log"
8+
"os"
9+
"strings"
10+
11+
"github.com/runletapp/crabfs/identity"
712

813
"github.com/runletapp/crabfs"
914
)
1015

11-
func relayStart(ctx context.Context, bootstrapPeers []string) {
12-
relay, err := crabfs.RelayNew(ctx, 1717, bootstrapPeers)
16+
func relayStart(ctx context.Context, bootstrapPeers []string, id identity.Identity) {
17+
relay, err := crabfs.RelayNew(ctx, 1717, bootstrapPeers, id)
1318
if err != nil {
1419
panic(err)
1520
}
@@ -22,11 +27,42 @@ func relayStart(ctx context.Context, bootstrapPeers []string) {
2227

2328
func main() {
2429
bootstrapPeer := flag.String("d", "", "bootstrap peer to dial")
30+
idFile := flag.String("i", "", "identity file")
2531
flag.Parse()
2632

2733
ctx := context.Background()
2834

35+
bootstrapPeers := []string{}
36+
if strings.TrimSpace(*bootstrapPeer) != "" {
37+
bootstrapPeers = append(bootstrapPeers, *bootstrapPeer)
38+
}
39+
40+
var id identity.Identity
41+
if strings.TrimSpace(*idFile) != "" {
42+
file, err := os.Open(*idFile)
43+
if err != nil {
44+
id, err = identity.CreateIdentity()
45+
if err != nil {
46+
panic(err)
47+
}
48+
data, err := id.Marshal()
49+
if err != nil {
50+
panic(err)
51+
}
52+
if err := ioutil.WriteFile(*idFile, data, 0644); err != nil {
53+
panic(err)
54+
}
55+
} else {
56+
defer file.Close()
57+
58+
id, err = identity.UnmarshalIdentity(file)
59+
if err != nil {
60+
panic(err)
61+
}
62+
}
63+
}
64+
2965
log.Printf("Starting relay...")
30-
relayStart(ctx, []string{*bootstrapPeer})
66+
relayStart(ctx, bootstrapPeers, id)
3167
<-ctx.Done()
3268
}

go.mod

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,26 @@ go 1.12
44

55
require (
66
github.com/GustavoKatel/SyncEvent v0.0.1
7-
github.com/coreos/go-semver v0.3.0 // indirect
8-
github.com/davecgh/go-spew v1.1.1 // indirect
97
github.com/gogo/protobuf v1.2.1
108
github.com/golang/mock v1.3.1
11-
github.com/golang/protobuf v1.3.0
9+
github.com/golang/protobuf v1.3.1
1210
github.com/ipfs/go-block-format v0.0.2
13-
github.com/ipfs/go-cid v0.0.1
14-
github.com/ipfs/go-datastore v0.0.3
15-
github.com/ipfs/go-ds-leveldb v0.0.1
11+
github.com/ipfs/go-cid v0.0.2
12+
github.com/ipfs/go-datastore v0.0.5
13+
github.com/ipfs/go-ds-leveldb v0.0.2
1614
github.com/ipfs/go-ipfs-blockstore v0.0.1
17-
github.com/libp2p/go-libp2p v0.0.12
18-
github.com/libp2p/go-libp2p-circuit v0.0.4
19-
github.com/libp2p/go-libp2p-discovery v0.0.1
20-
github.com/libp2p/go-libp2p-host v0.0.1
21-
github.com/libp2p/go-libp2p-kad-dht v0.0.7
22-
github.com/libp2p/go-libp2p-kbucket v0.1.1 // indirect
23-
github.com/libp2p/go-libp2p-net v0.0.2
24-
github.com/libp2p/go-libp2p-peerstore v0.0.2
25-
github.com/libp2p/go-libp2p-record v0.0.1
26-
github.com/libp2p/go-libp2p-routing v0.0.1
27-
github.com/mr-tron/base58 v1.1.1 // indirect
28-
github.com/multiformats/go-multiaddr v0.0.2
29-
github.com/multiformats/go-multihash v0.0.1
15+
github.com/libp2p/go-libp2p v0.1.0
16+
github.com/libp2p/go-libp2p-circuit v0.1.0
17+
github.com/libp2p/go-libp2p-core v0.0.2
18+
github.com/libp2p/go-libp2p-discovery v0.1.0
19+
github.com/libp2p/go-libp2p-host v0.1.0
20+
github.com/libp2p/go-libp2p-kad-dht v0.1.0
21+
github.com/libp2p/go-libp2p-net v0.1.0
22+
github.com/libp2p/go-libp2p-peerstore v0.1.0
23+
github.com/libp2p/go-libp2p-record v0.1.0
24+
github.com/libp2p/go-libp2p-routing v0.1.0
25+
github.com/multiformats/go-multiaddr v0.0.4
26+
github.com/multiformats/go-multihash v0.0.5
3027
github.com/stretchr/testify v1.3.0
31-
golang.org/x/sys v0.0.0-20190302025703-b6889370fb10 // indirect
28+
google.golang.org/appengine v1.4.0 // indirect
3229
)

0 commit comments

Comments
 (0)