diff --git a/cmd/fsd/main.go b/cmd/fsd/main.go index 562c199..8227497 100644 --- a/cmd/fsd/main.go +++ b/cmd/fsd/main.go @@ -12,7 +12,6 @@ import ( "syscall" "github.com/libp2p/go-libp2p/core/crypto" - "github.com/libp2p/go-libp2p/core/peer" "go.sia.tech/fsd/build" "go.sia.tech/fsd/config" shttp "go.sia.tech/fsd/http" @@ -99,7 +98,7 @@ func main() { } defer ds.Close() - privateKey, publicKey, _ := crypto.GenerateEd25519Key(frand.Reader) + privateKey, _, _ := crypto.GenerateEd25519Key(frand.Reader) store := ipfs.NewRenterdBlockStore(ds, cfg.Renterd) node, err := ipfs.NewNode(ctx, privateKey, cfg.IPFS, store) @@ -142,13 +141,8 @@ func main() { } }() - peerID, err := peer.IDFromPublicKey(publicKey) - if err != nil { - log.Fatal("failed to get peer id", zap.Error(err)) - } - log.Info("fsd started", - zap.Stringer("peerID", peerID), + zap.Stringer("peerID", node.PeerID()), zap.String("apiAddress", apiListener.Addr().String()), zap.String("gatewayAddress", gatewayListener.Addr().String()), zap.String("version", build.Version()), diff --git a/ipfs/node.go b/ipfs/node.go index 81ac74b..f351b8a 100644 --- a/ipfs/node.go +++ b/ipfs/node.go @@ -32,6 +32,7 @@ var bootstrapPeers = []peer.AddrInfo{ mustParsePeer("/ip4/104.131.131.82/udp/4001/quic/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"), } +// A Node is a minimal IPFS node type Node struct { dht *kdht.IpfsDHT host host.Host @@ -42,6 +43,7 @@ type Node struct { bitswap *bitswap.Bitswap } +// Close closes the node func (n *Node) Close() error { n.dht.Close() n.bitswap.Close() @@ -80,6 +82,7 @@ func mustParsePeer(s string) peer.AddrInfo { return *info } +// NewNode creates a new IPFS node func NewNode(ctx context.Context, privateKey crypto.PrivKey, cfg config.IPFS, blockstore blockstore.Blockstore) (*Node, error) { cmgr, err := connmgr.NewConnManager(600, 900) if err != nil { diff --git a/ipfs/node_test.go b/ipfs/node_test.go index ee75536..4d68184 100644 --- a/ipfs/node_test.go +++ b/ipfs/node_test.go @@ -162,6 +162,7 @@ func TestTest(t *testing.T) { downloadCtx, cancel := context.WithTimeout(ctx, 15*time.Second) defer cancel() + // note: this currently only downloads the root CID. Need to walk the DAG r, err := node.DownloadCID(downloadCtx, c) if err != nil { t.Fatal(err) diff --git a/ipfs/store.go b/ipfs/store.go index e5afab7..681514c 100644 --- a/ipfs/store.go +++ b/ipfs/store.go @@ -13,14 +13,19 @@ import ( "go.uber.org/zap" ) -// A Store implements the IPFS blockstore interface type ( + // A Store is a persistent store for IPFS blocks Store interface { GetBlock(ctx context.Context, c cid.Cid) (Block, error) HasBlock(ctx context.Context, c cid.Cid) (bool, error) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) } + // A RenterdBlockStore is a blockstore backed by a renterd node IPFS blocks + // are stored in a local database and backed by a renterd node. The primary + // difference between this and a normal IPFS blockstore is that an object is + // stored on the renterd node in one piece and the offsets for each block + // are stored in the database. RenterdBlockStore struct { store Store log *zap.Logger