From 5f1b9a18f16e07a53fe36ad92e87de6d7e583142 Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet Date: Thu, 26 Jun 2014 01:14:26 -0700 Subject: [PATCH 01/45] skeleton. This commit was moved from ipfs/go-block-format@c41fc61096f7956cda505139c1fab038d8857551 --- blocks/blocks.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 blocks/blocks.go diff --git a/blocks/blocks.go b/blocks/blocks.go new file mode 100644 index 000000000..fd7124651 --- /dev/null +++ b/blocks/blocks.go @@ -0,0 +1,14 @@ +package blocks + +import ( + "github.com/jbenet/go-ipfs/bitswap" + "github.com/jbenet/go-ipfs/storage" +) + +// Blocks is the ipfs blocks service. It is the way +// to retrieve blocks by the higher level ipfs modules + +type BlockService struct { + Local *storage.Storage + Remote *bitswap.BitSwap +} From 621be423259f05fa10f9a35a3de21713ea326208 Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet Date: Sat, 5 Jul 2014 15:32:08 -0700 Subject: [PATCH 02/45] block service This commit was moved from ipfs/go-block-format@1832342c6123385dae0132d9a84ff3952d29945e --- blocks/blocks.go | 57 ++++++++++++++++++++++++++++++++++++--- blocks/blocks_test.go | 62 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 blocks/blocks_test.go diff --git a/blocks/blocks.go b/blocks/blocks.go index fd7124651..284e555ff 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -1,14 +1,63 @@ package blocks import ( - "github.com/jbenet/go-ipfs/bitswap" - "github.com/jbenet/go-ipfs/storage" + "fmt" + ds "github.com/jbenet/datastore.go" + u "github.com/jbenet/go-ipfs/util" + mh "github.com/jbenet/go-multihash" ) // Blocks is the ipfs blocks service. It is the way // to retrieve blocks by the higher level ipfs modules +type Block struct { + Multihash mh.Multihash + Data []byte +} + +func NewBlock(data []byte) (*Block, error) { + h, err := u.Hash(data) + if err != nil { + return nil, err + } + return &Block{Data: data, Multihash: h}, nil +} + +func (b *Block) Key() u.Key { + return u.Key(b.Multihash) +} + type BlockService struct { - Local *storage.Storage - Remote *bitswap.BitSwap + Datastore ds.Datastore + // Remote *bitswap.BitSwap // eventually. +} + +func NewBlockService(d ds.Datastore) (*BlockService, error) { + if d == nil { + return nil, fmt.Errorf("BlockService requires valid datastore") + } + return &BlockService{Datastore: d}, nil +} + +func (s *BlockService) AddBlock(b *Block) error { + dsk := ds.NewKey(string(b.Key())) + return s.Datastore.Put(dsk, b.Data) +} + +func (s *BlockService) GetBlock(k u.Key) (*Block, error) { + dsk := ds.NewKey(string(k)) + datai, err := s.Datastore.Get(dsk) + if err != nil { + return nil, err + } + + data, ok := datai.([]byte) + if !ok { + return nil, fmt.Errorf("data associated with %s is not a []byte", k) + } + + return &Block{ + Multihash: mh.Multihash(k), + Data: data, + }, nil } diff --git a/blocks/blocks_test.go b/blocks/blocks_test.go new file mode 100644 index 000000000..6ee6c3d36 --- /dev/null +++ b/blocks/blocks_test.go @@ -0,0 +1,62 @@ +package blocks + +import ( + "bytes" + "fmt" + ds "github.com/jbenet/datastore.go" + u "github.com/jbenet/go-ipfs/util" + "testing" +) + +func TestBlocks(t *testing.T) { + + d := ds.NewMapDatastore() + bs, err := NewBlockService(d) + if err != nil { + t.Error("failed to construct block service", err) + return + } + + b, err := NewBlock([]byte("beep boop")) + if err != nil { + t.Error("failed to construct block", err) + return + } + + h, err := u.Hash([]byte("beep boop")) + if err != nil { + t.Error("failed to hash data", err) + return + } + + if !bytes.Equal(b.Multihash, h) { + t.Error("Block Multihash and data multihash not equal") + } + + if b.Key() != u.Key(h) { + t.Error("Block key and data multihash key not equal") + } + + err = bs.AddBlock(b) + if err != nil { + t.Error("failed to add block to BlockService", err) + return + } + + b2, err := bs.GetBlock(b.Key()) + if err != nil { + t.Error("failed to retrieve block from BlockService", err) + return + } + + if b.Key() != b2.Key() { + t.Error("Block keys not equal.") + } + + if !bytes.Equal(b.Data, b2.Data) { + t.Error("Block data is not equal.") + } + + fmt.Printf("key: %s\n", b.Key()) + fmt.Printf("data: %v\n", b.Data) +} From e5e3e4a68ef3732c1fc7e2c383c39e8646166a9f Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet Date: Sat, 5 Jul 2014 15:38:17 -0700 Subject: [PATCH 03/45] block get returned. This commit was moved from ipfs/go-block-format@0b50629387252b9feb341124119ac97f4b97a88b --- blocks/blocks.go | 7 ++++--- blocks/blocks_test.go | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index 284e555ff..8d5f64e05 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -39,9 +39,10 @@ func NewBlockService(d ds.Datastore) (*BlockService, error) { return &BlockService{Datastore: d}, nil } -func (s *BlockService) AddBlock(b *Block) error { - dsk := ds.NewKey(string(b.Key())) - return s.Datastore.Put(dsk, b.Data) +func (s *BlockService) AddBlock(b *Block) (u.Key, error) { + k := b.Key() + dsk := ds.NewKey(string(k)) + return k, s.Datastore.Put(dsk, b.Data) } func (s *BlockService) GetBlock(k u.Key) (*Block, error) { diff --git a/blocks/blocks_test.go b/blocks/blocks_test.go index 6ee6c3d36..ec3738330 100644 --- a/blocks/blocks_test.go +++ b/blocks/blocks_test.go @@ -37,12 +37,16 @@ func TestBlocks(t *testing.T) { t.Error("Block key and data multihash key not equal") } - err = bs.AddBlock(b) + k, err := bs.AddBlock(b) if err != nil { t.Error("failed to add block to BlockService", err) return } + if k != b.Key() { + t.Error("returned key is not equal to block key", err) + } + b2, err := bs.GetBlock(b.Key()) if err != nil { t.Error("failed to retrieve block from BlockService", err) From fd6d6c6ac9336e29d2085bc056ed2d7068a9b725 Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet Date: Mon, 21 Jul 2014 08:05:27 -0700 Subject: [PATCH 04/45] go lint link errors left: - protocol buffers output is not lint-friendly This commit was moved from ipfs/go-block-format@19745ca2714e69a8ade12fc6f376846feb9413b9 --- blocks/blocks.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index 8d5f64e05..4d5e9e952 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -7,14 +7,14 @@ import ( mh "github.com/jbenet/go-multihash" ) -// Blocks is the ipfs blocks service. It is the way +// Block is the ipfs blocks service. It is the way // to retrieve blocks by the higher level ipfs modules - type Block struct { Multihash mh.Multihash Data []byte } +// NewBlock creates a Block object from opaque data. It will hash the data. func NewBlock(data []byte) (*Block, error) { h, err := u.Hash(data) if err != nil { @@ -23,15 +23,19 @@ func NewBlock(data []byte) (*Block, error) { return &Block{Data: data, Multihash: h}, nil } +// Key returns the block's Multihash as a Key value. func (b *Block) Key() u.Key { return u.Key(b.Multihash) } +// BlockService is a block datastore. +// It uses an internal `datastore.Datastore` instance to store values. type BlockService struct { Datastore ds.Datastore // Remote *bitswap.BitSwap // eventually. } +// NewBlockService creates a BlockService with given datastore instance. func NewBlockService(d ds.Datastore) (*BlockService, error) { if d == nil { return nil, fmt.Errorf("BlockService requires valid datastore") @@ -39,12 +43,15 @@ func NewBlockService(d ds.Datastore) (*BlockService, error) { return &BlockService{Datastore: d}, nil } +// AddBlock adds a particular block to the service, Putting it into the datastore. func (s *BlockService) AddBlock(b *Block) (u.Key, error) { k := b.Key() dsk := ds.NewKey(string(k)) return k, s.Datastore.Put(dsk, b.Data) } +// GetBlock retrieves a particular block from the service, +// Getting it from the datastore using the key (hash). func (s *BlockService) GetBlock(k u.Key) (*Block, error) { dsk := ds.NewKey(string(k)) datai, err := s.Datastore.Get(dsk) From 8d1c161dbabb45b129e6e7abe73dabf192107468 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sun, 24 Aug 2014 18:13:05 -0700 Subject: [PATCH 05/45] basic implementation of bitswap, needs testing/verification that it works This commit was moved from ipfs/go-block-format@10eab98a40050bc472e30dd88d7af641ab141946 --- blocks/blocks.go | 44 -------------------------------------------- 1 file changed, 44 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index 4d5e9e952..45aee6ab2 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -1,8 +1,6 @@ package blocks import ( - "fmt" - ds "github.com/jbenet/datastore.go" u "github.com/jbenet/go-ipfs/util" mh "github.com/jbenet/go-multihash" ) @@ -27,45 +25,3 @@ func NewBlock(data []byte) (*Block, error) { func (b *Block) Key() u.Key { return u.Key(b.Multihash) } - -// BlockService is a block datastore. -// It uses an internal `datastore.Datastore` instance to store values. -type BlockService struct { - Datastore ds.Datastore - // Remote *bitswap.BitSwap // eventually. -} - -// NewBlockService creates a BlockService with given datastore instance. -func NewBlockService(d ds.Datastore) (*BlockService, error) { - if d == nil { - return nil, fmt.Errorf("BlockService requires valid datastore") - } - return &BlockService{Datastore: d}, nil -} - -// AddBlock adds a particular block to the service, Putting it into the datastore. -func (s *BlockService) AddBlock(b *Block) (u.Key, error) { - k := b.Key() - dsk := ds.NewKey(string(k)) - return k, s.Datastore.Put(dsk, b.Data) -} - -// GetBlock retrieves a particular block from the service, -// Getting it from the datastore using the key (hash). -func (s *BlockService) GetBlock(k u.Key) (*Block, error) { - dsk := ds.NewKey(string(k)) - datai, err := s.Datastore.Get(dsk) - if err != nil { - return nil, err - } - - data, ok := datai.([]byte) - if !ok { - return nil, fmt.Errorf("data associated with %s is not a []byte", k) - } - - return &Block{ - Multihash: mh.Multihash(k), - Data: data, - }, nil -} From 61326fea99c61868cbb83baacd21880a7f106801 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Mon, 25 Aug 2014 09:44:42 -0700 Subject: [PATCH 06/45] more work on bitswap and other code cleanup This commit was moved from ipfs/go-block-format@548035708f6979b8cc946ee94cedc334c5d21083 --- blocks/blocks_test.go | 66 ------------------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 blocks/blocks_test.go diff --git a/blocks/blocks_test.go b/blocks/blocks_test.go deleted file mode 100644 index ec3738330..000000000 --- a/blocks/blocks_test.go +++ /dev/null @@ -1,66 +0,0 @@ -package blocks - -import ( - "bytes" - "fmt" - ds "github.com/jbenet/datastore.go" - u "github.com/jbenet/go-ipfs/util" - "testing" -) - -func TestBlocks(t *testing.T) { - - d := ds.NewMapDatastore() - bs, err := NewBlockService(d) - if err != nil { - t.Error("failed to construct block service", err) - return - } - - b, err := NewBlock([]byte("beep boop")) - if err != nil { - t.Error("failed to construct block", err) - return - } - - h, err := u.Hash([]byte("beep boop")) - if err != nil { - t.Error("failed to hash data", err) - return - } - - if !bytes.Equal(b.Multihash, h) { - t.Error("Block Multihash and data multihash not equal") - } - - if b.Key() != u.Key(h) { - t.Error("Block key and data multihash key not equal") - } - - k, err := bs.AddBlock(b) - if err != nil { - t.Error("failed to add block to BlockService", err) - return - } - - if k != b.Key() { - t.Error("returned key is not equal to block key", err) - } - - b2, err := bs.GetBlock(b.Key()) - if err != nil { - t.Error("failed to retrieve block from BlockService", err) - return - } - - if b.Key() != b2.Key() { - t.Error("Block keys not equal.") - } - - if !bytes.Equal(b.Data, b2.Data) { - t.Error("Block data is not equal.") - } - - fmt.Printf("key: %s\n", b.Key()) - fmt.Printf("data: %v\n", b.Data) -} From cdd5425a8174fed32b5ed5c1487cc59508b15fb5 Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Tue, 9 Sep 2014 22:39:42 -0700 Subject: [PATCH 07/45] vendor dependencies with godep dependencies are vendored into Godeps/_workspace and commit versions are recorded in Godeps.json update datastore to e89f0511 update go.crypto This commit was moved from ipfs/go-block-format@058fa431aab414db83e307fffd5edafe7aca2e44 --- blocks/blocks.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index 45aee6ab2..b514f85d9 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -1,8 +1,8 @@ package blocks import ( + mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash" u "github.com/jbenet/go-ipfs/util" - mh "github.com/jbenet/go-multihash" ) // Block is the ipfs blocks service. It is the way From 7985dbd5f131c299eee05011d9304967461930ea Mon Sep 17 00:00:00 2001 From: Jeromy Date: Mon, 15 Sep 2014 06:07:03 +0000 Subject: [PATCH 08/45] add basic test for blocks package #59 This commit was moved from ipfs/go-block-format@ab55ab95a034d050c9de25b078974ae1fdfbea2a --- blocks/blocks.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index b514f85d9..c58ab9f20 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -5,8 +5,7 @@ import ( u "github.com/jbenet/go-ipfs/util" ) -// Block is the ipfs blocks service. It is the way -// to retrieve blocks by the higher level ipfs modules +// Block is a singular block of data in ipfs type Block struct { Multihash mh.Multihash Data []byte From 72b18476a4ab64e1f968f541bbfd251a990a0054 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Mon, 15 Sep 2014 06:08:49 +0000 Subject: [PATCH 09/45] add basic test for blocks package #59 (actually add file) This commit was moved from ipfs/go-block-format@f524411f93b33bb6b27833698a490aad052d8a75 --- blocks/blocks_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 blocks/blocks_test.go diff --git a/blocks/blocks_test.go b/blocks/blocks_test.go new file mode 100644 index 000000000..915d84c02 --- /dev/null +++ b/blocks/blocks_test.go @@ -0,0 +1,25 @@ +package blocks + +import "testing" + +func TestBlocksBasic(t *testing.T) { + + // Test empty data + empty := []byte{} + _, err := NewBlock(empty) + if err != nil { + t.Fatal(err) + } + + // Test nil case + _, err = NewBlock(nil) + if err != nil { + t.Fatal(err) + } + + // Test some data + _, err = NewBlock([]byte("Hello world!")) + if err != nil { + t.Fatal(err) + } +} From e95be6041e145499c7ede13f9a2c3751af53f188 Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet Date: Mon, 6 Oct 2014 02:26:50 -0700 Subject: [PATCH 10/45] u.Hash - error the u.Hash error can be safely ignored (panic) because multihash only fails from the selection of hash function. If the fn + length are valid, it won't error. cc @whyrusleeping This commit was moved from ipfs/go-block-format@a83b9037e41538cf30791b037a7f82d7cf544998 --- blocks/blocks.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index c58ab9f20..b45c1d1fb 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -13,11 +13,7 @@ type Block struct { // NewBlock creates a Block object from opaque data. It will hash the data. func NewBlock(data []byte) (*Block, error) { - h, err := u.Hash(data) - if err != nil { - return nil, err - } - return &Block{Data: data, Multihash: h}, nil + return &Block{Data: data, Multihash: u.Hash(data)}, nil } // Key returns the block's Multihash as a Key value. From ca7a70a1dc4a64528515a63d0fa32647b89f70b3 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Tue, 7 Oct 2014 20:46:01 +0000 Subject: [PATCH 11/45] removed error from return type of blocks.NewBlock() This commit was moved from ipfs/go-block-format@7e576d41df4e7d7e1ac0bc39d657239facead6cc --- blocks/blocks.go | 4 ++-- blocks/blocks_test.go | 15 +++------------ 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index b45c1d1fb..696c774ab 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -12,8 +12,8 @@ type Block struct { } // NewBlock creates a Block object from opaque data. It will hash the data. -func NewBlock(data []byte) (*Block, error) { - return &Block{Data: data, Multihash: u.Hash(data)}, nil +func NewBlock(data []byte) *Block { + return &Block{Data: data, Multihash: u.Hash(data)} } // Key returns the block's Multihash as a Key value. diff --git a/blocks/blocks_test.go b/blocks/blocks_test.go index 915d84c02..53a852275 100644 --- a/blocks/blocks_test.go +++ b/blocks/blocks_test.go @@ -6,20 +6,11 @@ func TestBlocksBasic(t *testing.T) { // Test empty data empty := []byte{} - _, err := NewBlock(empty) - if err != nil { - t.Fatal(err) - } + NewBlock(empty) // Test nil case - _, err = NewBlock(nil) - if err != nil { - t.Fatal(err) - } + NewBlock(nil) // Test some data - _, err = NewBlock([]byte("Hello world!")) - if err != nil { - t.Fatal(err) - } + NewBlock([]byte("Hello world!")) } From 8e033c113a0ea39a3058fb56d71d39306997ace8 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sun, 26 Oct 2014 00:45:40 +0000 Subject: [PATCH 12/45] lots of logging This commit was moved from ipfs/go-block-format@d1dd0be392b98f812d035c4b0d65fee39224120a --- blocks/blocks.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/blocks/blocks.go b/blocks/blocks.go index 696c774ab..9bf556f5a 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -1,6 +1,8 @@ package blocks import ( + "fmt" + mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash" u "github.com/jbenet/go-ipfs/util" ) @@ -20,3 +22,7 @@ func NewBlock(data []byte) *Block { func (b *Block) Key() u.Key { return u.Key(b.Multihash) } + +func (b *Block) String() string { + return fmt.Sprintf("[Block %s]", b.Key()) +} From ea91942a7d8ce57f0bd9b8d93f79ed7091a60069 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Wed, 29 Oct 2014 18:34:53 +0000 Subject: [PATCH 13/45] address comments from PR This commit was moved from ipfs/go-block-format@7e7367637a45c7bba657f1f96a5821d22ef0a000 --- blocks/blocks.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/blocks/blocks.go b/blocks/blocks.go index 9bf556f5a..b87cf5a32 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -1,6 +1,7 @@ package blocks import ( + "errors" "fmt" mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash" @@ -18,6 +19,16 @@ func NewBlock(data []byte) *Block { return &Block{Data: data, Multihash: u.Hash(data)} } +func NewBlockWithHash(data []byte, h mh.Multihash) (*Block, error) { + if u.Debug { + chk := u.Hash(data) + if string(chk) != string(h) { + return nil, errors.New("Data did not match given hash!") + } + } + return &Block{Data: data, Multihash: h}, nil +} + // Key returns the block's Multihash as a Key value. func (b *Block) Key() u.Key { return u.Key(b.Multihash) From a54188e581b0b0b9c0df7e8efb60f2b7c725bd45 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Mon, 3 Nov 2014 03:53:16 +0000 Subject: [PATCH 14/45] a few more comments This commit was moved from ipfs/go-block-format@267aeca6e1f4415678ce7474aa985ea4631aeb9f --- blocks/blocks.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/blocks/blocks.go b/blocks/blocks.go index b87cf5a32..1a94ee499 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -19,6 +19,9 @@ func NewBlock(data []byte) *Block { return &Block{Data: data, Multihash: u.Hash(data)} } +// NewBlockWithHash creates a new block when the hash of the data +// is already known, this is used to save time in situations where +// we are able to be confident that the data is correct func NewBlockWithHash(data []byte, h mh.Multihash) (*Block, error) { if u.Debug { chk := u.Hash(data) From 09ebe4adcb79e9181b095a1ec4e2c056b3365f8a Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sat, 8 Nov 2014 13:43:43 -0800 Subject: [PATCH 15/45] write a few package doc strings to improve look of godoc This commit was moved from ipfs/go-block-format@4928657781512cd3f2f0252eee90af7f926f2bad --- blocks/blocks.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/blocks/blocks.go b/blocks/blocks.go index 1a94ee499..46fd2e126 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -1,3 +1,5 @@ +// package blocks contains the lowest level of ipfs data structures, +// the raw block with a checksum. package blocks import ( From 979c81ce90420f3488a8134909c24ab8da4fd45b Mon Sep 17 00:00:00 2001 From: Jeromy Date: Wed, 18 Feb 2015 08:18:19 +0000 Subject: [PATCH 16/45] add worker to bitswap for reproviding new blocks This commit was moved from ipfs/go-block-format@be14adba02790a14d7bfb9dd5b769c1b1ba8d738 --- blocks/blocks.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/blocks/blocks.go b/blocks/blocks.go index 46fd2e126..e0d7624c1 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -42,3 +42,9 @@ func (b *Block) Key() u.Key { func (b *Block) String() string { return fmt.Sprintf("[Block %s]", b.Key()) } + +func (b *Block) Loggable() map[string]interface{} { + return map[string]interface{}{ + "block": b.Key().String(), + } +} From 4ec8d23d855339aeebf67cfcc47cffe720964636 Mon Sep 17 00:00:00 2001 From: Ho-Sheng Hsiao Date: Mon, 30 Mar 2015 20:04:32 -0700 Subject: [PATCH 17/45] Reorged imports from jbenet/go-ipfs to ipfs/go-ipfs - Modified Godeps/Godeps.json by hand - [TEST] Updated welcome docs hash to sharness - [TEST] Updated contact doc - [TEST] disabled breaking test (t0080-repo refs local) This commit was moved from ipfs/go-block-format@f3800ad4aee5c412893f3caa0403fa3e619b3190 --- blocks/blocks.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index e0d7624c1..d38ece82a 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -6,8 +6,8 @@ import ( "errors" "fmt" - mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash" - u "github.com/jbenet/go-ipfs/util" + mh "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash" + u "github.com/ipfs/go-ipfs/util" ) // Block is a singular block of data in ipfs From 2802309dc683b9de3f6b0c96cea6156799998d54 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Mon, 1 Jun 2015 16:10:08 -0700 Subject: [PATCH 18/45] move util.Key into its own package under blocks This commit was moved from ipfs/go-block-format@30244e2e12f92217233dab67452d1e22ef39e709 --- blocks/blocks.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index d38ece82a..ccd779c62 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -7,6 +7,7 @@ import ( "fmt" mh "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash" + key "github.com/ipfs/go-ipfs/blocks/key" u "github.com/ipfs/go-ipfs/util" ) @@ -35,8 +36,8 @@ func NewBlockWithHash(data []byte, h mh.Multihash) (*Block, error) { } // Key returns the block's Multihash as a Key value. -func (b *Block) Key() u.Key { - return u.Key(b.Multihash) +func (b *Block) Key() key.Key { + return key.Key(b.Multihash) } func (b *Block) String() string { From 747d9d4d8553bf66cba0cc90253692c8665e1da2 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Tue, 9 Feb 2016 10:56:19 -0800 Subject: [PATCH 19/45] Use gx vendored go-ipfs-utils where possible For the rest of the packages in util, move them to thirdparty and update the references. util is gone! License: MIT Signed-off-by: Jeromy This commit was moved from ipfs/go-block-format@f079d172668b0040f15d2d72069f5b8caba74cc3 --- blocks/blocks.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index ccd779c62..bcf58f747 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -6,9 +6,9 @@ import ( "errors" "fmt" - mh "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash" key "github.com/ipfs/go-ipfs/blocks/key" - u "github.com/ipfs/go-ipfs/util" + mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash" + u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" ) // Block is a singular block of data in ipfs From 8580d6f7a99b9cede3d4f628326e28aa7ece25d5 Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Thu, 5 May 2016 18:00:43 -0400 Subject: [PATCH 20/45] Make blocks.Block an interface. License: MIT Signed-off-by: Kevin Atkinson This commit was moved from ipfs/go-block-format@92cc3f1e3d5e2f96239419070a050c3c0e236bc3 --- blocks/blocks.go | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index bcf58f747..777ab4c90 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -11,40 +11,56 @@ import ( u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" ) +type Block interface { + Multihash() mh.Multihash + Data() []byte + Key() key.Key + String() string + Loggable() map[string]interface{} +} + // Block is a singular block of data in ipfs -type Block struct { - Multihash mh.Multihash - Data []byte +type RawBlock struct { + multihash mh.Multihash + data []byte } // NewBlock creates a Block object from opaque data. It will hash the data. -func NewBlock(data []byte) *Block { - return &Block{Data: data, Multihash: u.Hash(data)} +func NewBlock(data []byte) *RawBlock { + return &RawBlock{data: data, multihash: u.Hash(data)} } // NewBlockWithHash creates a new block when the hash of the data // is already known, this is used to save time in situations where // we are able to be confident that the data is correct -func NewBlockWithHash(data []byte, h mh.Multihash) (*Block, error) { +func NewBlockWithHash(data []byte, h mh.Multihash) (*RawBlock, error) { if u.Debug { chk := u.Hash(data) if string(chk) != string(h) { return nil, errors.New("Data did not match given hash!") } } - return &Block{Data: data, Multihash: h}, nil + return &RawBlock{data: data, multihash: h}, nil +} + +func (b *RawBlock) Multihash() mh.Multihash { + return b.multihash +} + +func (b *RawBlock) Data() []byte { + return b.data } // Key returns the block's Multihash as a Key value. -func (b *Block) Key() key.Key { - return key.Key(b.Multihash) +func (b *RawBlock) Key() key.Key { + return key.Key(b.multihash) } -func (b *Block) String() string { +func (b *RawBlock) String() string { return fmt.Sprintf("[Block %s]", b.Key()) } -func (b *Block) Loggable() map[string]interface{} { +func (b *RawBlock) Loggable() map[string]interface{} { return map[string]interface{}{ "block": b.Key().String(), } From 23a51d25ddea749fc5799daf8e4f4dfc61a58f81 Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Thu, 5 May 2016 23:24:23 -0400 Subject: [PATCH 21/45] Rename blocks.RawBlock to blocks.BasicBlock. License: MIT Signed-off-by: Kevin Atkinson This commit was moved from ipfs/go-block-format@1e01b02f967b25d4f454fefac2e1893263a3bbe8 --- blocks/blocks.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index 777ab4c90..d5f4df700 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -20,47 +20,47 @@ type Block interface { } // Block is a singular block of data in ipfs -type RawBlock struct { +type BasicBlock struct { multihash mh.Multihash data []byte } // NewBlock creates a Block object from opaque data. It will hash the data. -func NewBlock(data []byte) *RawBlock { - return &RawBlock{data: data, multihash: u.Hash(data)} +func NewBlock(data []byte) *BasicBlock { + return &BasicBlock{data: data, multihash: u.Hash(data)} } // NewBlockWithHash creates a new block when the hash of the data // is already known, this is used to save time in situations where // we are able to be confident that the data is correct -func NewBlockWithHash(data []byte, h mh.Multihash) (*RawBlock, error) { +func NewBlockWithHash(data []byte, h mh.Multihash) (*BasicBlock, error) { if u.Debug { chk := u.Hash(data) if string(chk) != string(h) { return nil, errors.New("Data did not match given hash!") } } - return &RawBlock{data: data, multihash: h}, nil + return &BasicBlock{data: data, multihash: h}, nil } -func (b *RawBlock) Multihash() mh.Multihash { +func (b *BasicBlock) Multihash() mh.Multihash { return b.multihash } -func (b *RawBlock) Data() []byte { +func (b *BasicBlock) Data() []byte { return b.data } // Key returns the block's Multihash as a Key value. -func (b *RawBlock) Key() key.Key { +func (b *BasicBlock) Key() key.Key { return key.Key(b.multihash) } -func (b *RawBlock) String() string { +func (b *BasicBlock) String() string { return fmt.Sprintf("[Block %s]", b.Key()) } -func (b *RawBlock) Loggable() map[string]interface{} { +func (b *BasicBlock) Loggable() map[string]interface{} { return map[string]interface{}{ "block": b.Key().String(), } From 7bba8de8a60150098720588f021c89ec73027f42 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Mon, 15 Aug 2016 12:46:49 +0200 Subject: [PATCH 22/45] test: 82% coverage on blocks License: MIT Signed-off-by: Jakub Sztandera This commit was moved from ipfs/go-block-format@e6e5593ad93dac96cc388af662f5b26827b4a2b5 --- blocks/blocks_test.go | 82 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/blocks/blocks_test.go b/blocks/blocks_test.go index 53a852275..1d7aa2e78 100644 --- a/blocks/blocks_test.go +++ b/blocks/blocks_test.go @@ -1,6 +1,12 @@ package blocks -import "testing" +import ( + "bytes" + "testing" + + mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash" + u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" +) func TestBlocksBasic(t *testing.T) { @@ -14,3 +20,77 @@ func TestBlocksBasic(t *testing.T) { // Test some data NewBlock([]byte("Hello world!")) } + +func TestData(t *testing.T) { + data := []byte("some data") + block := NewBlock(data) + + if !bytes.Equal(block.Data(), data) { + t.Error("data is wrong") + } +} + +func TestHash(t *testing.T) { + data := []byte("some other data") + block := NewBlock(data) + + hash, err := mh.Sum(data, mh.SHA2_256, -1) + if err != nil { + t.Fatal(err) + } + + if !bytes.Equal(block.Multihash(), hash) { + t.Error("wrong multihash") + } +} + +func TestKey(t *testing.T) { + data := []byte("yet another data") + block := NewBlock(data) + key := block.Key() + + if !bytes.Equal(block.Multihash(), key.ToMultihash()) { + t.Error("key contains wrong data") + } +} + +func TestManualHash(t *testing.T) { + oldDebugState := u.Debug + defer (func() { + u.Debug = oldDebugState + })() + + data := []byte("I can't figure out more names .. data") + hash, err := mh.Sum(data, mh.SHA2_256, -1) + if err != nil { + t.Fatal(err) + } + + u.Debug = false + block, err := NewBlockWithHash(data, hash) + if err != nil { + t.Fatal(err) + } + + if !bytes.Equal(block.Multihash(), hash) { + t.Error("wrong multihash") + } + + data[5] = byte((uint32(data[5]) + 5) % 256) // Transfrom hash to be different + block, err = NewBlockWithHash(data, hash) + if err != nil { + t.Fatal(err) + } + + if !bytes.Equal(block.Multihash(), hash) { + t.Error("wrong multihash") + } + + u.Debug = true + + block, err = NewBlockWithHash(data, hash) + if err == nil { + t.Fatal(err) + } + +} From 2f35330a910959543a879f41d99b3f167560e63e Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Mon, 15 Aug 2016 17:23:44 +0200 Subject: [PATCH 23/45] test: do explicit error check License: MIT Signed-off-by: Jakub Sztandera This commit was moved from ipfs/go-block-format@7614cdadde0b79d095a23f6fb0461428d5411f95 --- blocks/blocks.go | 4 +++- blocks/blocks_test.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index d5f4df700..ea4bf70cd 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -11,6 +11,8 @@ import ( u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" ) +var errWrongHash = errors.New("Data did not match given hash!") + type Block interface { Multihash() mh.Multihash Data() []byte @@ -37,7 +39,7 @@ func NewBlockWithHash(data []byte, h mh.Multihash) (*BasicBlock, error) { if u.Debug { chk := u.Hash(data) if string(chk) != string(h) { - return nil, errors.New("Data did not match given hash!") + return nil, errWrongHash } } return &BasicBlock{data: data, multihash: h}, nil diff --git a/blocks/blocks_test.go b/blocks/blocks_test.go index 1d7aa2e78..6c218beec 100644 --- a/blocks/blocks_test.go +++ b/blocks/blocks_test.go @@ -89,7 +89,7 @@ func TestManualHash(t *testing.T) { u.Debug = true block, err = NewBlockWithHash(data, hash) - if err == nil { + if err != errWrongHash { t.Fatal(err) } From 42fdef9d8c775401f12684e3337e666068ec1b5f Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 16 Aug 2016 12:42:18 +0200 Subject: [PATCH 24/45] blocks: rename errWrongHash to ErrWrongHash License: MIT Signed-off-by: Jakub Sztandera This commit was moved from ipfs/go-block-format@bf963fc3d2e8c871da9bf03350360acc6750542d --- blocks/blocks.go | 4 ++-- blocks/blocks_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index ea4bf70cd..202e471ce 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -11,7 +11,7 @@ import ( u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" ) -var errWrongHash = errors.New("Data did not match given hash!") +var ErrWrongHash = errors.New("Data did not match given hash!") type Block interface { Multihash() mh.Multihash @@ -39,7 +39,7 @@ func NewBlockWithHash(data []byte, h mh.Multihash) (*BasicBlock, error) { if u.Debug { chk := u.Hash(data) if string(chk) != string(h) { - return nil, errWrongHash + return nil, ErrWrongHash } } return &BasicBlock{data: data, multihash: h}, nil diff --git a/blocks/blocks_test.go b/blocks/blocks_test.go index 6c218beec..1fecff844 100644 --- a/blocks/blocks_test.go +++ b/blocks/blocks_test.go @@ -89,7 +89,7 @@ func TestManualHash(t *testing.T) { u.Debug = true block, err = NewBlockWithHash(data, hash) - if err != errWrongHash { + if err != ErrWrongHash { t.Fatal(err) } From c2fbd6719a0ee603d37ea1a33a3fca6c63c4139b Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 16 Aug 2016 17:36:18 +0200 Subject: [PATCH 25/45] docs: decapitalize error message in blocks.go License: MIT Signed-off-by: Jakub Sztandera This commit was moved from ipfs/go-block-format@4588bc62155fba47ca9be277e388933aab0551eb --- blocks/blocks.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index 202e471ce..c41e1323a 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -11,7 +11,7 @@ import ( u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" ) -var ErrWrongHash = errors.New("Data did not match given hash!") +var ErrWrongHash = errors.New("data did not match given hash!") type Block interface { Multihash() mh.Multihash From b6e3126a953945f092664ad7bb54f268711fdd76 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Thu, 1 Sep 2016 07:50:27 -0700 Subject: [PATCH 26/45] integrate CIDv0 License: MIT Signed-off-by: Jeromy This commit was moved from ipfs/go-block-format@22ebb793fa4aec9a2c90df040149807ddc3a2fbd --- blocks/blocks.go | 10 ++++++++-- blocks/blocks_test.go | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index c41e1323a..d8f5a11d8 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -7,15 +7,17 @@ import ( "fmt" key "github.com/ipfs/go-ipfs/blocks/key" + mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" + cid "gx/ipfs/QmfSc2xehWmWLnwwYR91Y8QF4xdASypTFVknutoKQS3GHp/go-cid" ) var ErrWrongHash = errors.New("data did not match given hash!") type Block interface { Multihash() mh.Multihash - Data() []byte + RawData() []byte Key() key.Key String() string Loggable() map[string]interface{} @@ -49,10 +51,14 @@ func (b *BasicBlock) Multihash() mh.Multihash { return b.multihash } -func (b *BasicBlock) Data() []byte { +func (b *BasicBlock) RawData() []byte { return b.data } +func (b *BasicBlock) Cid() *cid.Cid { + return cid.NewCidV0(b.multihash) +} + // Key returns the block's Multihash as a Key value. func (b *BasicBlock) Key() key.Key { return key.Key(b.multihash) diff --git a/blocks/blocks_test.go b/blocks/blocks_test.go index 1fecff844..07f13de29 100644 --- a/blocks/blocks_test.go +++ b/blocks/blocks_test.go @@ -25,7 +25,7 @@ func TestData(t *testing.T) { data := []byte("some data") block := NewBlock(data) - if !bytes.Equal(block.Data(), data) { + if !bytes.Equal(block.RawData(), data) { t.Error("data is wrong") } } From 271afae99e788f2b58a9433d0c25fd5ec6037c4f Mon Sep 17 00:00:00 2001 From: George Antoniadis Date: Fri, 9 Sep 2016 15:41:28 +0100 Subject: [PATCH 27/45] Extract key and datastore License: MIT Signed-off-by: George Antoniadis This commit was moved from ipfs/go-block-format@ea54261b26c22012113fb1ffe7a3a5c891352962 --- blocks/blocks.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index d8f5a11d8..88740775f 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -6,7 +6,7 @@ import ( "errors" "fmt" - key "github.com/ipfs/go-ipfs/blocks/key" + key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" From d9fb8ccc5c1b1477905c4b6e426804e2dc8f694b Mon Sep 17 00:00:00 2001 From: Jeromy Date: Wed, 5 Oct 2016 15:49:08 -0700 Subject: [PATCH 28/45] update to libp2p 4.0.1 and propogate other changes License: MIT Signed-off-by: Jeromy This commit was moved from ipfs/go-block-format@dd1aa7309b064c3be1484357db5f725c3932be54 --- blocks/blocks.go | 8 ++++---- blocks/blocks_test.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index 88740775f..4b26a22dd 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -6,11 +6,11 @@ import ( "errors" "fmt" - key "gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key" + key "gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key" - mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash" - u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" - cid "gx/ipfs/QmfSc2xehWmWLnwwYR91Y8QF4xdASypTFVknutoKQS3GHp/go-cid" + mh "gx/ipfs/QmYDds3421prZgqKbLpEK7T9Aa2eVdQ7o3YarX1LVLdP2J/go-multihash" + cid "gx/ipfs/QmakyCk6Vnn16WEKjbkxieZmM2YLTzkFWizbmGowoYPjro/go-cid" + u "gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util" ) var ErrWrongHash = errors.New("data did not match given hash!") diff --git a/blocks/blocks_test.go b/blocks/blocks_test.go index 07f13de29..4d5d5908f 100644 --- a/blocks/blocks_test.go +++ b/blocks/blocks_test.go @@ -4,8 +4,8 @@ import ( "bytes" "testing" - mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash" - u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" + mh "gx/ipfs/QmYDds3421prZgqKbLpEK7T9Aa2eVdQ7o3YarX1LVLdP2J/go-multihash" + u "gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util" ) func TestBlocksBasic(t *testing.T) { From a71a90c11d7ca1f845aca13d1eae6969fd2ce94a Mon Sep 17 00:00:00 2001 From: Jeromy Date: Fri, 7 Oct 2016 11:14:45 -0700 Subject: [PATCH 29/45] cid: integrate cid into bitswap and blockstores License: MIT Signed-off-by: Jeromy This commit was moved from ipfs/go-block-format@09c41e5b3e3d80701d8ba1728d5d3ddb0524cebc --- blocks/blocks.go | 33 ++++++++++++++------------------- blocks/blocks_test.go | 15 +++++++++------ 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index 4b26a22dd..e7b2b1042 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -6,8 +6,6 @@ import ( "errors" "fmt" - key "gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key" - mh "gx/ipfs/QmYDds3421prZgqKbLpEK7T9Aa2eVdQ7o3YarX1LVLdP2J/go-multihash" cid "gx/ipfs/QmakyCk6Vnn16WEKjbkxieZmM2YLTzkFWizbmGowoYPjro/go-cid" u "gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util" @@ -18,37 +16,39 @@ var ErrWrongHash = errors.New("data did not match given hash!") type Block interface { Multihash() mh.Multihash RawData() []byte - Key() key.Key + Cid() *cid.Cid String() string Loggable() map[string]interface{} } // Block is a singular block of data in ipfs type BasicBlock struct { - multihash mh.Multihash - data []byte + cid *cid.Cid + data []byte } // NewBlock creates a Block object from opaque data. It will hash the data. func NewBlock(data []byte) *BasicBlock { - return &BasicBlock{data: data, multihash: u.Hash(data)} + // TODO: fix assumptions + return &BasicBlock{data: data, cid: cid.NewCidV0(u.Hash(data))} } // NewBlockWithHash creates a new block when the hash of the data // is already known, this is used to save time in situations where // we are able to be confident that the data is correct -func NewBlockWithHash(data []byte, h mh.Multihash) (*BasicBlock, error) { +func NewBlockWithCid(data []byte, c *cid.Cid) (*BasicBlock, error) { if u.Debug { - chk := u.Hash(data) - if string(chk) != string(h) { + // TODO: fix assumptions + chkc := cid.NewCidV0(u.Hash(data)) + if !chkc.Equals(c) { return nil, ErrWrongHash } } - return &BasicBlock{data: data, multihash: h}, nil + return &BasicBlock{data: data, cid: c}, nil } func (b *BasicBlock) Multihash() mh.Multihash { - return b.multihash + return b.cid.Hash() } func (b *BasicBlock) RawData() []byte { @@ -56,20 +56,15 @@ func (b *BasicBlock) RawData() []byte { } func (b *BasicBlock) Cid() *cid.Cid { - return cid.NewCidV0(b.multihash) -} - -// Key returns the block's Multihash as a Key value. -func (b *BasicBlock) Key() key.Key { - return key.Key(b.multihash) + return b.cid } func (b *BasicBlock) String() string { - return fmt.Sprintf("[Block %s]", b.Key()) + return fmt.Sprintf("[Block %s]", b.Cid()) } func (b *BasicBlock) Loggable() map[string]interface{} { return map[string]interface{}{ - "block": b.Key().String(), + "block": b.Cid().String(), } } diff --git a/blocks/blocks_test.go b/blocks/blocks_test.go index 4d5d5908f..4ce12866e 100644 --- a/blocks/blocks_test.go +++ b/blocks/blocks_test.go @@ -5,6 +5,7 @@ import ( "testing" mh "gx/ipfs/QmYDds3421prZgqKbLpEK7T9Aa2eVdQ7o3YarX1LVLdP2J/go-multihash" + cid "gx/ipfs/QmakyCk6Vnn16WEKjbkxieZmM2YLTzkFWizbmGowoYPjro/go-cid" u "gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util" ) @@ -44,12 +45,12 @@ func TestHash(t *testing.T) { } } -func TestKey(t *testing.T) { +func TestCid(t *testing.T) { data := []byte("yet another data") block := NewBlock(data) - key := block.Key() + c := block.Cid() - if !bytes.Equal(block.Multihash(), key.ToMultihash()) { + if !bytes.Equal(block.Multihash(), c.Hash()) { t.Error("key contains wrong data") } } @@ -66,8 +67,10 @@ func TestManualHash(t *testing.T) { t.Fatal(err) } + c := cid.NewCidV0(hash) + u.Debug = false - block, err := NewBlockWithHash(data, hash) + block, err := NewBlockWithCid(data, c) if err != nil { t.Fatal(err) } @@ -77,7 +80,7 @@ func TestManualHash(t *testing.T) { } data[5] = byte((uint32(data[5]) + 5) % 256) // Transfrom hash to be different - block, err = NewBlockWithHash(data, hash) + block, err = NewBlockWithCid(data, c) if err != nil { t.Fatal(err) } @@ -88,7 +91,7 @@ func TestManualHash(t *testing.T) { u.Debug = true - block, err = NewBlockWithHash(data, hash) + block, err = NewBlockWithCid(data, c) if err != ErrWrongHash { t.Fatal(err) } From 429e98bf492332836c2d665c8fdf3c442533b554 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sat, 8 Oct 2016 17:59:41 -0700 Subject: [PATCH 30/45] bitswap: protocol extension to handle cids This change adds the /ipfs/bitswap/1.1.0 protocol. The new protocol adds a 'payload' field to the protobuf message and deprecates the existing 'blocks' field. The 'payload' field is an array of pairs of cid prefixes and block data. The cid prefixes are used to ensure the correct codecs and hash functions are used to handle the block on the receiving end. License: MIT Signed-off-by: Jeromy This commit was moved from ipfs/go-block-format@51106c2e52325da701557746a90a8d80460417c2 --- blocks/blocks.go | 2 +- blocks/blocks_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index e7b2b1042..d4a385f29 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -6,8 +6,8 @@ import ( "errors" "fmt" + cid "gx/ipfs/QmXUuRadqDq5BuFWzVU6VuKaSjTcNm1gNCtLvvP1TJCW4z/go-cid" mh "gx/ipfs/QmYDds3421prZgqKbLpEK7T9Aa2eVdQ7o3YarX1LVLdP2J/go-multihash" - cid "gx/ipfs/QmakyCk6Vnn16WEKjbkxieZmM2YLTzkFWizbmGowoYPjro/go-cid" u "gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util" ) diff --git a/blocks/blocks_test.go b/blocks/blocks_test.go index 4ce12866e..031210b9a 100644 --- a/blocks/blocks_test.go +++ b/blocks/blocks_test.go @@ -4,8 +4,8 @@ import ( "bytes" "testing" + cid "gx/ipfs/QmXUuRadqDq5BuFWzVU6VuKaSjTcNm1gNCtLvvP1TJCW4z/go-cid" mh "gx/ipfs/QmYDds3421prZgqKbLpEK7T9Aa2eVdQ7o3YarX1LVLdP2J/go-multihash" - cid "gx/ipfs/QmakyCk6Vnn16WEKjbkxieZmM2YLTzkFWizbmGowoYPjro/go-cid" u "gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util" ) From 26f954023ecffccad81227ab07ac52e69b0b3c76 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sun, 9 Oct 2016 12:59:36 -0700 Subject: [PATCH 31/45] merkledag: change 'Node' to be an interface Also change existing 'Node' type to 'ProtoNode' and use that most everywhere for now. As we move forward with the integration we will try and use the Node interface in more places that we're currently using ProtoNode. License: MIT Signed-off-by: Jeromy This commit was moved from ipfs/go-block-format@9a4a2e3b68ff0c4d0ab442ade882d63d62946370 --- blocks/blocks.go | 1 - 1 file changed, 1 deletion(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index d4a385f29..4d5b64422 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -14,7 +14,6 @@ import ( var ErrWrongHash = errors.New("data did not match given hash!") type Block interface { - Multihash() mh.Multihash RawData() []byte Cid() *cid.Cid String() string From 40829d29f2856d831a06d8fa100431af6501f7a4 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sat, 15 Oct 2016 09:06:44 -0700 Subject: [PATCH 32/45] unixfs: allow use of raw merkledag nodes for unixfs files License: MIT Signed-off-by: Jeromy This commit was moved from ipfs/go-block-format@bc1f635bc7af9b770289f114294445d2a78770d9 --- blocks/blocks.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index 4d5b64422..ff125367f 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -37,8 +37,11 @@ func NewBlock(data []byte) *BasicBlock { // we are able to be confident that the data is correct func NewBlockWithCid(data []byte, c *cid.Cid) (*BasicBlock, error) { if u.Debug { - // TODO: fix assumptions - chkc := cid.NewCidV0(u.Hash(data)) + chkc, err := c.Prefix().Sum(data) + if err != nil { + return nil, err + } + if !chkc.Equals(c) { return nil, ErrWrongHash } From 91cc22bd9dddebe708d17a3a73a6a1bd0e545ad1 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Mon, 24 Oct 2016 20:39:27 -0700 Subject: [PATCH 33/45] update to new cid and ipld node packages License: MIT Signed-off-by: Jeromy This commit was moved from ipfs/go-block-format@5344a460ad40d1c80b46efab6034044b50d468a3 --- blocks/blocks.go | 2 +- blocks/blocks_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index ff125367f..1079d37ef 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -6,7 +6,7 @@ import ( "errors" "fmt" - cid "gx/ipfs/QmXUuRadqDq5BuFWzVU6VuKaSjTcNm1gNCtLvvP1TJCW4z/go-cid" + cid "gx/ipfs/QmXfiyr2RWEXpVDdaYnD2HNiBk6UBddsvEP4RPfXb6nGqY/go-cid" mh "gx/ipfs/QmYDds3421prZgqKbLpEK7T9Aa2eVdQ7o3YarX1LVLdP2J/go-multihash" u "gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util" ) diff --git a/blocks/blocks_test.go b/blocks/blocks_test.go index 031210b9a..32d47a867 100644 --- a/blocks/blocks_test.go +++ b/blocks/blocks_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - cid "gx/ipfs/QmXUuRadqDq5BuFWzVU6VuKaSjTcNm1gNCtLvvP1TJCW4z/go-cid" + cid "gx/ipfs/QmXfiyr2RWEXpVDdaYnD2HNiBk6UBddsvEP4RPfXb6nGqY/go-cid" mh "gx/ipfs/QmYDds3421prZgqKbLpEK7T9Aa2eVdQ7o3YarX1LVLdP2J/go-multihash" u "gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util" ) From 10d5dcca3f285c660d5ea1d71cacf281b35f8f3a Mon Sep 17 00:00:00 2001 From: Richard Littauer Date: Fri, 1 Jul 2016 18:36:55 +0100 Subject: [PATCH 34/45] Changed so only explicit ipfs cli commands are lowercased License: MIT Signed-off-by: Richard Littauer This commit was moved from ipfs/go-block-format@73c5f440569f9c02b7985d3678e290cb1b9e5f32 --- blocks/blocks.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index 1079d37ef..b50d62026 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -1,4 +1,4 @@ -// package blocks contains the lowest level of ipfs data structures, +// package blocks contains the lowest level of IPFS data structures, // the raw block with a checksum. package blocks From 019b0276cd051d3b295a361b5d7533651e9f6ae6 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Tue, 15 Nov 2016 18:00:49 -0800 Subject: [PATCH 35/45] update to newer ipld node interface with Copy and better Tree License: MIT Signed-off-by: Jeromy This commit was moved from ipfs/go-block-format@2fd2df7bbc777e8b739c2e2eb2f884b3ea987ed1 --- blocks/blocks.go | 2 +- blocks/blocks_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index b50d62026..0151cc78d 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -6,9 +6,9 @@ import ( "errors" "fmt" - cid "gx/ipfs/QmXfiyr2RWEXpVDdaYnD2HNiBk6UBddsvEP4RPfXb6nGqY/go-cid" mh "gx/ipfs/QmYDds3421prZgqKbLpEK7T9Aa2eVdQ7o3YarX1LVLdP2J/go-multihash" u "gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util" + cid "gx/ipfs/QmcEcrBAMrwMyhSjXt4yfyPpzgSuV8HLHavnfmiKCSRqZU/go-cid" ) var ErrWrongHash = errors.New("data did not match given hash!") diff --git a/blocks/blocks_test.go b/blocks/blocks_test.go index 32d47a867..b50bd826d 100644 --- a/blocks/blocks_test.go +++ b/blocks/blocks_test.go @@ -4,9 +4,9 @@ import ( "bytes" "testing" - cid "gx/ipfs/QmXfiyr2RWEXpVDdaYnD2HNiBk6UBddsvEP4RPfXb6nGqY/go-cid" mh "gx/ipfs/QmYDds3421prZgqKbLpEK7T9Aa2eVdQ7o3YarX1LVLdP2J/go-multihash" u "gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util" + cid "gx/ipfs/QmcEcrBAMrwMyhSjXt4yfyPpzgSuV8HLHavnfmiKCSRqZU/go-cid" ) func TestBlocksBasic(t *testing.T) { From 0bc86d63259c7976a81261439298f6bdf4a16669 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Mon, 28 Nov 2016 22:29:38 -0800 Subject: [PATCH 36/45] bubble up go-datastore deps License: MIT Signed-off-by: Jeromy This commit was moved from ipfs/go-block-format@cf388be8c31a0e9af23f72157d2f4dee35c2fe5e --- blocks/blocks.go | 2 +- blocks/blocks_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index 0151cc78d..680065633 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -8,7 +8,7 @@ import ( mh "gx/ipfs/QmYDds3421prZgqKbLpEK7T9Aa2eVdQ7o3YarX1LVLdP2J/go-multihash" u "gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util" - cid "gx/ipfs/QmcEcrBAMrwMyhSjXt4yfyPpzgSuV8HLHavnfmiKCSRqZU/go-cid" + cid "gx/ipfs/QmcTcsTvfaeEBRFo1TkFgT8sRmgi1n1LTZpecfVP8fzpGD/go-cid" ) var ErrWrongHash = errors.New("data did not match given hash!") diff --git a/blocks/blocks_test.go b/blocks/blocks_test.go index b50bd826d..d60862974 100644 --- a/blocks/blocks_test.go +++ b/blocks/blocks_test.go @@ -6,7 +6,7 @@ import ( mh "gx/ipfs/QmYDds3421prZgqKbLpEK7T9Aa2eVdQ7o3YarX1LVLdP2J/go-multihash" u "gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util" - cid "gx/ipfs/QmcEcrBAMrwMyhSjXt4yfyPpzgSuV8HLHavnfmiKCSRqZU/go-cid" + cid "gx/ipfs/QmcTcsTvfaeEBRFo1TkFgT8sRmgi1n1LTZpecfVP8fzpGD/go-cid" ) func TestBlocksBasic(t *testing.T) { From 577a9fa24c16aa32979437d5eaf5e76765b8bfdd Mon Sep 17 00:00:00 2001 From: Jeromy Date: Thu, 2 Feb 2017 20:09:02 -0800 Subject: [PATCH 37/45] update go-multihash and bubble up deps License: MIT Signed-off-by: Jeromy This commit was moved from ipfs/go-block-format@5029bc3eba51c81d021753740636d11946d5c6d9 --- blocks/blocks.go | 6 +++--- blocks/blocks_test.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index 680065633..3010b30ef 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -6,9 +6,9 @@ import ( "errors" "fmt" - mh "gx/ipfs/QmYDds3421prZgqKbLpEK7T9Aa2eVdQ7o3YarX1LVLdP2J/go-multihash" - u "gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util" - cid "gx/ipfs/QmcTcsTvfaeEBRFo1TkFgT8sRmgi1n1LTZpecfVP8fzpGD/go-cid" + cid "gx/ipfs/QmV5gPoRsjN1Gid3LMdNZTyfCtP2DsvqEbMAmz82RmmiGk/go-cid" + u "gx/ipfs/QmZuY8aV7zbNXVy6DyN9SmnuH3o9nG852F4aTiSBpts8d1/go-ipfs-util" + mh "gx/ipfs/QmbZ6Cee2uHjG7hf19qLHppgKDRtaG4CVtMzdmK9VCVqLu/go-multihash" ) var ErrWrongHash = errors.New("data did not match given hash!") diff --git a/blocks/blocks_test.go b/blocks/blocks_test.go index d60862974..5a81b63cb 100644 --- a/blocks/blocks_test.go +++ b/blocks/blocks_test.go @@ -4,9 +4,9 @@ import ( "bytes" "testing" - mh "gx/ipfs/QmYDds3421prZgqKbLpEK7T9Aa2eVdQ7o3YarX1LVLdP2J/go-multihash" - u "gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util" - cid "gx/ipfs/QmcTcsTvfaeEBRFo1TkFgT8sRmgi1n1LTZpecfVP8fzpGD/go-cid" + cid "gx/ipfs/QmV5gPoRsjN1Gid3LMdNZTyfCtP2DsvqEbMAmz82RmmiGk/go-cid" + u "gx/ipfs/QmZuY8aV7zbNXVy6DyN9SmnuH3o9nG852F4aTiSBpts8d1/go-ipfs-util" + mh "gx/ipfs/QmbZ6Cee2uHjG7hf19qLHppgKDRtaG4CVtMzdmK9VCVqLu/go-multihash" ) func TestBlocksBasic(t *testing.T) { From 48848d0bb4887affb8de7d7147a2ce5234611098 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Fri, 24 Mar 2017 16:36:46 +0100 Subject: [PATCH 38/45] Make Golint happy in the blocks submodule. This has required changing the order of some parameters and adding HashOnRead to the Blockstore interface (which I have in turn added to all the wrapper implementations). License: MIT Signed-off-by: Hector Sanjuan This commit was moved from ipfs/go-block-format@cb5edc30ad4515c109c48f4fabae3f085984e1e6 --- blocks/blocks.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index 3010b30ef..0c7c18fc0 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -1,5 +1,6 @@ -// package blocks contains the lowest level of IPFS data structures, -// the raw block with a checksum. +// Package blocks contains the lowest level of IPFS data structures. +// A block is raw data accompanied by a CID. The CID contains the multihash +// corresponding to the block. package blocks import ( @@ -11,8 +12,11 @@ import ( mh "gx/ipfs/QmbZ6Cee2uHjG7hf19qLHppgKDRtaG4CVtMzdmK9VCVqLu/go-multihash" ) -var ErrWrongHash = errors.New("data did not match given hash!") +// ErrWrongHash is returned when the Cid of a block is not the expected +// according to the contents. It is currently used only when debugging. +var ErrWrongHash = errors.New("data did not match given hash") +// Block provides abstraction for blocks implementations. type Block interface { RawData() []byte Cid() *cid.Cid @@ -20,7 +24,8 @@ type Block interface { Loggable() map[string]interface{} } -// Block is a singular block of data in ipfs +// A BasicBlock is a singular block of data in ipfs. It implements the Block +// interface. type BasicBlock struct { cid *cid.Cid data []byte @@ -32,9 +37,9 @@ func NewBlock(data []byte) *BasicBlock { return &BasicBlock{data: data, cid: cid.NewCidV0(u.Hash(data))} } -// NewBlockWithHash creates a new block when the hash of the data +// NewBlockWithCid creates a new block when the hash of the data // is already known, this is used to save time in situations where -// we are able to be confident that the data is correct +// we are able to be confident that the data is correct. func NewBlockWithCid(data []byte, c *cid.Cid) (*BasicBlock, error) { if u.Debug { chkc, err := c.Prefix().Sum(data) @@ -49,22 +54,27 @@ func NewBlockWithCid(data []byte, c *cid.Cid) (*BasicBlock, error) { return &BasicBlock{data: data, cid: c}, nil } +// Multihash returns the hash contained in the block CID. func (b *BasicBlock) Multihash() mh.Multihash { return b.cid.Hash() } +// RawData returns the block raw contents as a byte slice. func (b *BasicBlock) RawData() []byte { return b.data } +// Cid returns the content identifier of the block. func (b *BasicBlock) Cid() *cid.Cid { return b.cid } +// String provides a human-readable representation of the block CID. func (b *BasicBlock) String() string { return fmt.Sprintf("[Block %s]", b.Cid()) } +// Loggable returns a go-log loggable item. func (b *BasicBlock) Loggable() map[string]interface{} { return map[string]interface{}{ "block": b.Cid().String(), From 6e3639a875acdf165bd4ba3ecc988731e7041574 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Fri, 24 Mar 2017 23:51:18 -0700 Subject: [PATCH 39/45] bubble up updates from go-multihash changes License: MIT Signed-off-by: Jeromy This commit was moved from ipfs/go-block-format@57a3a5dbafebbf18518b3d1a68b1567bf60dc874 --- blocks/blocks.go | 6 +++--- blocks/blocks_test.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index 0c7c18fc0..1f6abe655 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -7,9 +7,9 @@ import ( "errors" "fmt" - cid "gx/ipfs/QmV5gPoRsjN1Gid3LMdNZTyfCtP2DsvqEbMAmz82RmmiGk/go-cid" - u "gx/ipfs/QmZuY8aV7zbNXVy6DyN9SmnuH3o9nG852F4aTiSBpts8d1/go-ipfs-util" - mh "gx/ipfs/QmbZ6Cee2uHjG7hf19qLHppgKDRtaG4CVtMzdmK9VCVqLu/go-multihash" + mh "gx/ipfs/QmVGtdTZdTFaLsaj2RwdVG8jcjNNcp1DE914DKZ2kHmXHw/go-multihash" + u "gx/ipfs/QmWbjfz3u6HkAdPh34dgPchGbQjob6LXLhAeCGii2TX69n/go-ipfs-util" + cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid" ) // ErrWrongHash is returned when the Cid of a block is not the expected diff --git a/blocks/blocks_test.go b/blocks/blocks_test.go index 5a81b63cb..c13d8368f 100644 --- a/blocks/blocks_test.go +++ b/blocks/blocks_test.go @@ -4,9 +4,9 @@ import ( "bytes" "testing" - cid "gx/ipfs/QmV5gPoRsjN1Gid3LMdNZTyfCtP2DsvqEbMAmz82RmmiGk/go-cid" - u "gx/ipfs/QmZuY8aV7zbNXVy6DyN9SmnuH3o9nG852F4aTiSBpts8d1/go-ipfs-util" - mh "gx/ipfs/QmbZ6Cee2uHjG7hf19qLHppgKDRtaG4CVtMzdmK9VCVqLu/go-multihash" + mh "gx/ipfs/QmVGtdTZdTFaLsaj2RwdVG8jcjNNcp1DE914DKZ2kHmXHw/go-multihash" + u "gx/ipfs/QmWbjfz3u6HkAdPh34dgPchGbQjob6LXLhAeCGii2TX69n/go-ipfs-util" + cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid" ) func TestBlocksBasic(t *testing.T) { From 45079f87e64edf55aa6423bf9093ec51d18b3e07 Mon Sep 17 00:00:00 2001 From: zramsay Date: Wed, 31 May 2017 16:56:11 -0400 Subject: [PATCH 40/45] apply the megacheck tool to improve code quality License: MIT Signed-off-by: Zach Ramsay This commit was moved from ipfs/go-block-format@558aaac2457087b9e59641ddc7d1949b819e5ccf --- blocks/blocks_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/blocks/blocks_test.go b/blocks/blocks_test.go index c13d8368f..e984a1772 100644 --- a/blocks/blocks_test.go +++ b/blocks/blocks_test.go @@ -91,9 +91,8 @@ func TestManualHash(t *testing.T) { u.Debug = true - block, err = NewBlockWithCid(data, c) + _, err = NewBlockWithCid(data, c) if err != ErrWrongHash { t.Fatal(err) } - } From 96bd65675cd15010798db8f61234d20e3dbcbc0e Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 16 Jun 2017 17:42:37 -0700 Subject: [PATCH 41/45] Migrate out of the IPFS repo. License: MIT Signed-off-by: Steven Allen This commit was moved from ipfs/go-block-format@7faeb7bf51b2b31d937f4448fed4eabac1083de8 --- blocks/LICENSE | 21 +++++++++++++++++++++ blocks/blocks.go | 8 ++++---- blocks/blocks_test.go | 6 +++--- 3 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 blocks/LICENSE diff --git a/blocks/LICENSE b/blocks/LICENSE new file mode 100644 index 000000000..8001ebee6 --- /dev/null +++ b/blocks/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014-2017 Juan Batiz-Benet + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/blocks/blocks.go b/blocks/blocks.go index 1f6abe655..0ae7b03d4 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -1,4 +1,4 @@ -// Package blocks contains the lowest level of IPFS data structures. +// Package blocks contains the lowest level of IPLD data structures. // A block is raw data accompanied by a CID. The CID contains the multihash // corresponding to the block. package blocks @@ -7,9 +7,9 @@ import ( "errors" "fmt" - mh "gx/ipfs/QmVGtdTZdTFaLsaj2RwdVG8jcjNNcp1DE914DKZ2kHmXHw/go-multihash" - u "gx/ipfs/QmWbjfz3u6HkAdPh34dgPchGbQjob6LXLhAeCGii2TX69n/go-ipfs-util" - cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid" + cid "github.com/ipfs/go-cid" + u "github.com/ipfs/go-ipfs-util" + mh "github.com/multiformats/go-multihash" ) // ErrWrongHash is returned when the Cid of a block is not the expected diff --git a/blocks/blocks_test.go b/blocks/blocks_test.go index e984a1772..18f0c1f38 100644 --- a/blocks/blocks_test.go +++ b/blocks/blocks_test.go @@ -4,9 +4,9 @@ import ( "bytes" "testing" - mh "gx/ipfs/QmVGtdTZdTFaLsaj2RwdVG8jcjNNcp1DE914DKZ2kHmXHw/go-multihash" - u "gx/ipfs/QmWbjfz3u6HkAdPh34dgPchGbQjob6LXLhAeCGii2TX69n/go-ipfs-util" - cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid" + cid "github.com/ipfs/go-cid" + u "github.com/ipfs/go-ipfs-util" + mh "github.com/multiformats/go-multihash" ) func TestBlocksBasic(t *testing.T) { From bb1977ec7ee6f414839ba696fcb18d6ff4ad768a Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Wed, 5 Sep 2018 01:47:09 -0400 Subject: [PATCH 42/45] gx update go-cid and fix code to use new Cid type This commit was moved from ipfs/go-block-format@ec5ea817e665f488a529046dc6aa12212a2c93f5 --- blocks/blocks.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/blocks/blocks.go b/blocks/blocks.go index 0ae7b03d4..3d3894b3f 100644 --- a/blocks/blocks.go +++ b/blocks/blocks.go @@ -19,7 +19,7 @@ var ErrWrongHash = errors.New("data did not match given hash") // Block provides abstraction for blocks implementations. type Block interface { RawData() []byte - Cid() *cid.Cid + Cid() cid.Cid String() string Loggable() map[string]interface{} } @@ -27,7 +27,7 @@ type Block interface { // A BasicBlock is a singular block of data in ipfs. It implements the Block // interface. type BasicBlock struct { - cid *cid.Cid + cid cid.Cid data []byte } @@ -40,7 +40,7 @@ func NewBlock(data []byte) *BasicBlock { // NewBlockWithCid creates a new block when the hash of the data // is already known, this is used to save time in situations where // we are able to be confident that the data is correct. -func NewBlockWithCid(data []byte, c *cid.Cid) (*BasicBlock, error) { +func NewBlockWithCid(data []byte, c cid.Cid) (*BasicBlock, error) { if u.Debug { chkc, err := c.Prefix().Sum(data) if err != nil { @@ -65,7 +65,7 @@ func (b *BasicBlock) RawData() []byte { } // Cid returns the content identifier of the block. -func (b *BasicBlock) Cid() *cid.Cid { +func (b *BasicBlock) Cid() cid.Cid { return b.cid } From 483a463afdeda4c7cf4fd5e8230a941f04bd38e7 Mon Sep 17 00:00:00 2001 From: Gus Eggert Date: Wed, 25 Jan 2023 20:26:24 +0100 Subject: [PATCH 43/45] chore: add a logo and some basics in the README (#37) --- README.md | 65 ++++++++++++++++++++++++++++++++++++++++++++++++------- logo.svg | 1 + 2 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 logo.svg diff --git a/README.md b/README.md index 06a4f1544..2720610af 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,66 @@ -go-libipfs -======================= +

+go-libipfs 🍌 +
+go-libipfs logo +
+

+

A library for building IPFS applications and implementations.

-> A library for building IPFS implementations +
-Go-libips is a library for building IPFS implementations and tools in Go. It contains reusable functionality useful for interacting and experimenting with IPFS. +[![Go Test](https://github.com/ipfs/go-libipfs/actions/workflows/go-test.yml/badge.svg)](https://github.com/ipfs/go-libipfs/actions/workflows/go-test.yml) +[![Go Docs](https://img.shields.io/badge/godoc-reference-blue.svg)](https://pkg.go.dev/github.com/ipfs/go-libipfs) +[![codecov](https://codecov.io/gh/ipfs/go-libipfs/branch/main/graph/badge.svg?token=9eG7d8fbCB)](https://codecov.io/gh/ipfs/go-libipfs) -This is also used by [Kubo](https://github.com/ipfs/kubo) for its core functionality. +## -Currently this library is a target for consolidating Go IPFS repositories, and will receive minor version releases as repositories are consolidated into it. We are initially focused on merely consolidating repositories, *not* refactoring across packages. Once repositories are mostly consolidated, *then* we will begin refactoring this library holistically. Individual components can still be worked on and refactored individually, but please refrain from trying to refactor across components. +Go-libips is a component library for building IPFS applications and implementations in Go. -## Contributing +Some scenarios in which you may find go-libipfs helpful: + +* You are building an application that interacts with the IPFS network +* You are building an IPFS implementation +* You want to reuse some components of IPFS such as its Kademlia DHT, Bitswap, data encoding, etc. +* You want to experiment with IPFS + +Go-libipfs powers [Kubo](https://github.com/ipfs/kubo), which is the most popular IPFS implementation, so its code has been battle-tested on the IPFS network for years, and is well-understood by the community. + +## What kind of components does go-libipfs have? + +Go-libipfs includes high-quality components useful for interacting with IPFS protocols, public and private IPFS networks, and content-addressed data, such as: + +- Content routing (DHT, delegated content routing, providing) +- Data transfer (gateways, Bitswap, incremental verification) +- Naming and mutability (name resolution, IPNS) +- Interacting with public and private IPFS networks +- Working with content-addressed data + +Go-libipfs aims to provide a cohesive interface into these components. Note that not all of the underlying components necessarily reside in this respository. + +## Getting started +TODO + +## Should I add my IPFS component to go-libipfs? +We happily accept external contributions! However, go-libipfs maintains a high quality bar, so code accepted into go-libipfs must meet some minimum maintenance criteria: + +* Actively maintained + * Must be actively used by, or will be included in software that is actively used by, a significant number of users or production systems. Code that is not actively used cannot be properly maintained. + * Must have multiple engineers who are willing and able to maintain the relevant code in go-libipfs for a long period of time. + * If either of these changes, go-libipfs maintainers will consider removing the component from go-libipfs. +* Adequately tested + * At least with unit tests + * Ideally also including integration tests with other components +* Adequately documented + * Godocs at minimum + * Complex components should have their own doc.go or README.md describing the component, its use cases, tradeoffs, design rationale, etc. +* If the maintainers are not go-libipfs maintainers, then the component must include a CODEOWNERS file with at least two code owners who can commit to reviewing PRs + +If you have some experimental component that you think would benefit the IPFS community, we suggest you build the component in your own repository until it's clear that there's community demand for it, and then open an issue in this repository to discuss including it in go-libipfs. + +## Help + +If you have questions, feel free to open an issue. You can also find the go-libipfs maintainers in [Slack](https://filecoin.io/slack/) at #go-libipfs-maintainers. -Contributions are welcome! This repository is part of the IPFS project and therefore governed by our [contributing guidelines](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md). ## License diff --git a/logo.svg b/logo.svg new file mode 100644 index 000000000..735f3ab80 --- /dev/null +++ b/logo.svg @@ -0,0 +1 @@ + \ No newline at end of file From 7a8eed3d5ad2e8ff79a3bf4341db329c43d9b83b Mon Sep 17 00:00:00 2001 From: Gus Eggert Date: Wed, 25 Jan 2023 14:30:56 -0500 Subject: [PATCH 44/45] chore: add codecov PR comment --- codecov.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 codecov.yml diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 000000000..8e342b16d --- /dev/null +++ b/codecov.yml @@ -0,0 +1,2 @@ +comment: + layout: "reach, diff, files" From 274ea524859e240889b35000e93b00e91bff55b4 Mon Sep 17 00:00:00 2001 From: Jorropo Date: Thu, 26 Jan 2023 06:46:29 +0100 Subject: [PATCH 45/45] blocks: remove LICENSE See: https://github.com/ipfs/go-libipfs/pull/36#discussion_r1087052898 --- blocks/LICENSE | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 blocks/LICENSE diff --git a/blocks/LICENSE b/blocks/LICENSE deleted file mode 100644 index 8001ebee6..000000000 --- a/blocks/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2014-2017 Juan Batiz-Benet - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE.