@cryptotaxi247 / kubo / commits / f718bd6a9

go lint

link errors left: - protocol buffers output is not lint-friendly

Juan Batiz-Benet committed Jul 21, 2014 at 08:05 UTC f718bd6a9239d1038cba32b884dc2c266f45c2df
17 files changed +134 -37
blocks/blocks.go
+9 -2
@@ -7,14 +7,14 @@ import (
7 mh "github.com/jbenet/go-multihash"
8 )
9
10 -// Blocks is the ipfs blocks service. It is the way
10 +// Block is the ipfs blocks service. It is the way
11 // to retrieve blocks by the higher level ipfs modules
12 -
12 type Block struct {
13 Multihash mh.Multihash
14 Data []byte
15 }
16
17 +// NewBlock creates a Block object from opaque data. It will hash the data.
18 func NewBlock(data []byte) (*Block, error) {
19 h, err := u.Hash(data)
20 if err != nil {
@@ -23,15 +23,19 @@ func NewBlock(data []byte) (*Block, error) {
23 return &Block{Data: data, Multihash: h}, nil
24 }
25
26 +// Key returns the block's Multihash as a Key value.
27 func (b *Block) Key() u.Key {
28 return u.Key(b.Multihash)
29 }
30
31 +// BlockService is a block datastore.
32 +// It uses an internal `datastore.Datastore` instance to store values.
33 type BlockService struct {
34 Datastore ds.Datastore
35 // Remote *bitswap.BitSwap // eventually.
36 }
37
38 +// NewBlockService creates a BlockService with given datastore instance.
39 func NewBlockService(d ds.Datastore) (*BlockService, error) {
40 if d == nil {
41 return nil, fmt.Errorf("BlockService requires valid datastore")
@@ -39,12 +43,15 @@ func NewBlockService(d ds.Datastore) (*BlockService, error) {
43 return &BlockService{Datastore: d}, nil
44 }
45
46 +// AddBlock adds a particular block to the service, Putting it into the datastore.
47 func (s *BlockService) AddBlock(b *Block) (u.Key, error) {
48 k := b.Key()
49 dsk := ds.NewKey(string(k))
50 return k, s.Datastore.Put(dsk, b.Data)
51 }
52
53 +// GetBlock retrieves a particular block from the service,
54 +// Getting it from the datastore using the key (hash).
55 func (s *BlockService) GetBlock(k u.Key) (*Block, error) {
56 dsk := ds.NewKey(string(k))
57 datai, err := s.Datastore.Get(dsk)
cli/add.go
+8 -7
@@ -14,7 +14,8 @@ import (
14 "path/filepath"
15 )
16
17 -var DepthLimitExceeded = fmt.Errorf("depth limit exceeded")
17 +// Error indicating the max depth has been exceded.
18 +var ErrDepthLimitExceeded = fmt.Errorf("depth limit exceeded")
19
20 var cmdIpfsAdd = &commander.Command{
21 UsageLine: "add",
@@ -57,10 +58,10 @@ func addCmd(c *commander.Command, inp []string) error {
58 _, err := addPath(n, fpath, depth)
59 if err != nil {
60 if !recursive {
60 - return fmt.Errorf("%s is a directory. Use -r to add recursively.", fpath)
61 - } else {
62 - u.PErr("error adding %s: %v\n", fpath, err)
61 + return fmt.Errorf("%s is a directory. Use -r to add recursively", fpath)
62 }
63 +
64 + u.PErr("error adding %s: %v\n", fpath, err)
65 }
66 }
67 return err
@@ -68,7 +69,7 @@ func addCmd(c *commander.Command, inp []string) error {
69
70 func addPath(n *core.IpfsNode, fpath string, depth int) (*dag.Node, error) {
71 if depth == 0 {
71 - return nil, DepthLimitExceeded
72 + return nil, ErrDepthLimitExceeded
73 }
74
75 fi, err := os.Stat(fpath)
@@ -78,9 +79,9 @@ func addPath(n *core.IpfsNode, fpath string, depth int) (*dag.Node, error) {
79
80 if fi.IsDir() {
81 return addDir(n, fpath, depth)
81 - } else {
82 - return addFile(n, fpath, depth)
82 }
83 +
84 + return addFile(n, fpath, depth)
85 }
86
87 func addDir(n *core.IpfsNode, fpath string, depth int) (*dag.Node, error) {
cli/ipfs.go
+1
@@ -10,6 +10,7 @@ import (
10 "os"
11 )
12
13 +// The IPFS command tree. It is an instance of `commander.Command`.
14 var CmdIpfs = &commander.Command{
15 UsageLine: "ipfs [<flags>] <command> [<args>]",
16 Short: "global versioned p2p merkledag file system",
cli/version.go
+1
@@ -5,6 +5,7 @@ import (
5 u "github.com/jbenet/go-ipfs/util"
6 )
7
8 +// The IPFS version.
9 const Version = "0.1.0"
10
11 var cmdIpfsVersion = &commander.Command{
config/config.go
+4
@@ -5,15 +5,18 @@ import (
5 u "github.com/jbenet/go-ipfs/util"
6 )
7
8 +// Identity tracks the configuration of the local node's identity.
9 type Identity struct {
10 PeerId string
11 }
12
13 +// Datastore tracks the configuration of the datastore.
14 type Datastore struct {
15 Type string
16 Path string
17 }
18
19 +// Config is used to load IPFS config files.
20 type Config struct {
21 Identity *Identity
22 Datastore *Datastore
@@ -29,6 +32,7 @@ var defaultConfigFile = `{
32 }
33 `
34
35 +// LoadConfig reads given file and returns the read config, or error.
36 func LoadConfig(filename string) (*Config, error) {
37 if len(filename) == 0 {
38 filename = defaultConfigFilePath
config/serialize.go
+4 -5
@@ -7,10 +7,7 @@ import (
7 "path"
8 )
9
10 -func ReadFile(filename string) ([]byte, error) {
11 - return ioutil.ReadFile(filename)
12 -}
13 -
10 +// WriteFile writes the given buffer `buf` into file named `filename`.
11 func WriteFile(filename string, buf []byte) error {
12 err := os.MkdirAll(path.Dir(filename), 0777)
13 if err != nil {
@@ -20,8 +17,9 @@ func WriteFile(filename string, buf []byte) error {
17 return ioutil.WriteFile(filename, buf, 0666)
18 }
19
20 +// ReadConfigFile reads the config from `filename` into `cfg`.
21 func ReadConfigFile(filename string, cfg *Config) error {
24 - buf, err := ReadFile(filename)
22 + buf, err := ioutil.ReadFile(filename)
23 if err != nil {
24 return err
25 }
@@ -29,6 +27,7 @@ func ReadConfigFile(filename string, cfg *Config) error {
27 return json.Unmarshal(buf, cfg)
28 }
29
30 +// WriteConfigFile writes the config from `cfg` into `filename`.
31 func WriteConfigFile(filename string, cfg *Config) error {
32 buf, err := json.MarshalIndent(cfg, "", " ")
33 if err != nil {
core/core.go
+3 -2
@@ -10,7 +10,7 @@ import (
10 peer "github.com/jbenet/go-ipfs/peer"
11 )
12
13 -// IPFS Core module. It represents an IPFS instance.
13 +// IpfsNode is IPFS Core module. It represents an IPFS instance.
14 type IpfsNode struct {
15
16 // the node's configuration
@@ -47,9 +47,10 @@ type IpfsNode struct {
47 // Namesys *namesys.Namesys
48 }
49
50 +// NewIpfsNode constructs a new IpfsNode based on the given config.
51 func NewIpfsNode(cfg *config.Config) (*IpfsNode, error) {
52 if cfg == nil {
52 - return nil, fmt.Errorf("configuration required.")
53 + return nil, fmt.Errorf("configuration required")
54 }
55
56 d, err := makeDatastore(cfg.Datastore)
dht/dht.go
+1 -1
@@ -4,4 +4,4 @@ package dht
4 // Coral and S/Kademlia modifications. It is used to
5 // implement the base IPFS Routing module.
6
7 -TODO. SEE https://github.com/jbenet/node-ipfs/blob/master/submodules/ipfs-dht/index.js
7 +// TODO. SEE https://github.com/jbenet/node-ipfs/blob/master/submodules/ipfs-dht/index.js
fuse/readonly/readonly.go
+14
@@ -16,26 +16,32 @@ import (
16 "time"
17 )
18
19 +// FileSystem is the readonly Ipfs Fuse Filesystem.
20 type FileSystem struct {
21 Ipfs *core.IpfsNode
22 }
23
24 +// NewFileSystem constructs new fs using given core.IpfsNode instance.
25 func NewFileSystem(ipfs *core.IpfsNode) *FileSystem {
26 return &FileSystem{Ipfs: ipfs}
27 }
28
29 +// Root constructs the Root of the filesystem, a Root object.
30 func (f FileSystem) Root() (fs.Node, fuse.Error) {
31 return &Root{Ipfs: f.Ipfs}, nil
32 }
33
34 +// Root is the root object of the filesystem tree.
35 type Root struct {
36 Ipfs *core.IpfsNode
37 }
38
39 +// Attr returns file attributes.
40 func (*Root) Attr() fuse.Attr {
41 return fuse.Attr{Mode: os.ModeDir | 0111} // -rw+x
42 }
43
44 +// Lookup performs a lookup under this node.
45 func (s *Root) Lookup(name string, intr fs.Intr) (fs.Node, fuse.Error) {
46 switch name {
47 case "mach_kernel", ".hidden", "._.":
@@ -52,15 +58,18 @@ func (s *Root) Lookup(name string, intr fs.Intr) (fs.Node, fuse.Error) {
58 return &Node{Ipfs: s.Ipfs, Nd: nd}, nil
59 }
60
61 +// ReadDir reads a particular directory. Disallowed for root.
62 func (*Root) ReadDir(intr fs.Intr) ([]fuse.Dirent, fuse.Error) {
63 return nil, fuse.EPERM
64 }
65
66 +// Node is the core object representing a filesystem tree node.
67 type Node struct {
68 Ipfs *core.IpfsNode
69 Nd *mdag.Node
70 }
71
72 +// Attr returns the attributes of a given node.
73 func (s *Node) Attr() fuse.Attr {
74 if len(s.Nd.Links) > 0 {
75 return fuse.Attr{Mode: os.ModeDir | 0555}
@@ -70,6 +79,7 @@ func (s *Node) Attr() fuse.Attr {
79 return fuse.Attr{Mode: 0444, Size: uint64(size)}
80 }
81
82 +// Lookup performs a lookup under this node.
83 func (s *Node) Lookup(name string, intr fs.Intr) (fs.Node, fuse.Error) {
84 nd, err := s.Ipfs.Resolver.ResolveLinks(s.Nd, []string{name})
85 if err != nil {
@@ -80,6 +90,7 @@ func (s *Node) Lookup(name string, intr fs.Intr) (fs.Node, fuse.Error) {
90 return &Node{Ipfs: s.Ipfs, Nd: nd}, nil
91 }
92
93 +// ReadDir reads the link structure as directory entries
94 func (s *Node) ReadDir(intr fs.Intr) ([]fuse.Dirent, fuse.Error) {
95 entries := make([]fuse.Dirent, len(s.Nd.Links))
96 for i, link := range s.Nd.Links {
@@ -96,10 +107,13 @@ func (s *Node) ReadDir(intr fs.Intr) ([]fuse.Dirent, fuse.Error) {
107 return nil, fuse.ENOENT
108 }
109
110 +// ReadAll reads the object data as file data
111 func (s *Node) ReadAll(intr fs.Intr) ([]byte, fuse.Error) {
112 return []byte(s.Nd.Data), nil
113 }
114
115 +// Mount mounts an IpfsNode instance at a particular path. It
116 +// serves until the process receives exit signals (to Unmount).
117 func Mount(ipfs *core.IpfsNode, fpath string) error {
118
119 sigc := make(chan os.Signal, 1)
importer/importer.go
+9 -4
@@ -8,13 +8,17 @@ import (
8 "os"
9 )
10
11 +// BlockSizeLimit specifies the maximum size an imported block can have.
12 var BlockSizeLimit = int64(1048576) // 1 MB
12 -var SizeLimitExceeded = fmt.Errorf("object size limit exceeded")
13 +
14 +// ErrSizeLimitExceeded signals that a block is larger than BlockSizeLimit.
15 +var ErrSizeLimitExceeded = fmt.Errorf("object size limit exceeded")
16
17 // todo: incremental construction with an ipfs node. dumping constructed
18 // objects into the datastore, to avoid buffering all in memory
19
17 -// size required for block construction
20 +// NewDagFromReader constructs a Merkle DAG from the given io.Reader.
21 +// size required for block construction.
22 func NewDagFromReader(r io.Reader, size int64) (*dag.Node, error) {
23 // todo: block-splitting based on rabin fingerprinting
24 // todo: block-splitting with user-defined function
@@ -22,7 +26,7 @@ func NewDagFromReader(r io.Reader, size int64) (*dag.Node, error) {
26
27 // totally just trusts the reported size. fix later.
28 if size > BlockSizeLimit { // 1 MB limit for now.
25 - return nil, SizeLimitExceeded
29 + return nil, ErrSizeLimitExceeded
30 }
31
32 // we're doing it live!
@@ -32,7 +36,7 @@ func NewDagFromReader(r io.Reader, size int64) (*dag.Node, error) {
36 }
37
38 if int64(len(buf)) > BlockSizeLimit {
35 - return nil, SizeLimitExceeded // lying punk.
39 + return nil, ErrSizeLimitExceeded // lying punk.
40 }
41
42 root := &dag.Node{Data: buf}
@@ -40,6 +44,7 @@ func NewDagFromReader(r io.Reader, size int64) (*dag.Node, error) {
44 return root, nil
45 }
46
47 +// NewDagFromFile constructs a Merkle DAG from the file at given path.
48 func NewDagFromFile(fpath string) (*dag.Node, error) {
49 stat, err := os.Stat(fpath)
50 if err != nil {
merkledag/coding.go
+9
@@ -8,6 +8,8 @@ import (
8 // for now, we use a PBNode intermediate thing.
9 // because native go objects are nice.
10
11 +// Unmarshal decodes raw data into a *Node instance.
12 +// The conversion uses an intermediate PBNode.
13 func (n *Node) Unmarshal(encoded []byte) error {
14 var pbn PBNode
15 if err := pbn.Unmarshal(encoded); err != nil {
@@ -29,6 +31,8 @@ func (n *Node) Unmarshal(encoded []byte) error {
31 return nil
32 }
33
34 +// MarshalTo encodes a *Node instance into a given byte slice.
35 +// The conversion uses an intermediate PBNode.
36 func (n *Node) MarshalTo(encoded []byte) error {
37 pbn := n.getPBNode()
38 if _, err := pbn.MarshalTo(encoded); err != nil {
@@ -37,6 +41,8 @@ func (n *Node) MarshalTo(encoded []byte) error {
41 return nil
42 }
43
44 +// Marshal encodes a *Node instance into a new byte slice.
45 +// The conversion uses an intermediate PBNode.
46 func (n *Node) Marshal() ([]byte, error) {
47 pbn := n.getPBNode()
48 data, err := pbn.Marshal()
@@ -60,6 +66,8 @@ func (n *Node) getPBNode() *PBNode {
66 return pbn
67 }
68
69 +// Encoded returns the encoded raw data version of a Node instance.
70 +// It may use a cached encoded version, unless the force flag is given.
71 func (n *Node) Encoded(force bool) ([]byte, error) {
72 if n.encoded == nil || force {
73 var err error
@@ -72,6 +80,7 @@ func (n *Node) Encoded(force bool) ([]byte, error) {
80 return n.encoded, nil
81 }
82
83 +// Decoded decodes raw data and returns a new Node instance.
84 func Decoded(encoded []byte) (*Node, error) {
85 n := &Node{}
86 err := n.Unmarshal(encoded)
merkledag/merkledag.go
+15 -7
@@ -7,11 +7,12 @@ import (
7 mh "github.com/jbenet/go-multihash"
8 )
9
10 -// can't use []byte/Multihash for keys :(
11 -// so have to convert Multihash bytes to string
10 +// NodeMap maps u.Keys to Nodes.
11 +// We cannot use []byte/Multihash for keys :(
12 +// so have to convert Multihash bytes to string (u.Key)
13 type NodeMap map[u.Key]*Node
14
14 -// A node in the IPFS Merkle DAG.
15 +// Node represents a node in the IPFS Merkle DAG.
16 // nodes have opaque data and a set of navigable links.
17 type Node struct {
18 Links []*Link
@@ -21,7 +22,7 @@ type Node struct {
22 encoded []byte
23 }
24
24 -// An IPFS Merkle DAG Link
25 +// Link represents an IPFS Merkle DAG Link between Nodes.
26 type Link struct {
27 // utf string name. should be unique per object
28 Name string // utf8
@@ -36,6 +37,7 @@ type Link struct {
37 Node *Node
38 }
39
40 +// AddNodeLink adds a link to another node.
41 func (n *Node) AddNodeLink(name string, that *Node) error {
42 s, err := that.Size()
43 if err != nil {
@@ -55,6 +57,8 @@ func (n *Node) AddNodeLink(name string, that *Node) error {
57 return nil
58 }
59
60 +// Size returns the total size of the data addressed by node,
61 +// including the total sizes of references.
62 func (n *Node) Size() (uint64, error) {
63 b, err := n.Encoded(false)
64 if err != nil {
@@ -68,6 +72,7 @@ func (n *Node) Size() (uint64, error) {
72 return s, nil
73 }
74
75 +// Multihash hashes the encoded data of this node.
76 func (n *Node) Multihash() (mh.Multihash, error) {
77 b, err := n.Encoded(false)
78 if err != nil {
@@ -77,18 +82,20 @@ func (n *Node) Multihash() (mh.Multihash, error) {
82 return u.Hash(b)
83 }
84
85 +// Key returns the Multihash as a key, for maps.
86 func (n *Node) Key() (u.Key, error) {
87 h, err := n.Multihash()
88 return u.Key(h), err
89 }
90
85 -// An IPFS Merkle DAG service.
86 -// the root is virtual (like a forest)
87 -// stores nodes' data in a blockService
91 +// DAGService is an IPFS Merkle DAG service.
92 +// - the root is virtual (like a forest)
93 +// - stores nodes' data in a BlockService
94 type DAGService struct {
95 Blocks *blocks.BlockService
96 }
97
98 +// Put adds a node to the DAGService, storing the block in the BlockService
99 func (n *DAGService) Put(nd *Node) (u.Key, error) {
100 if n == nil {
101 return "", fmt.Errorf("DAGService is nil")
@@ -107,6 +114,7 @@ func (n *DAGService) Put(nd *Node) (u.Key, error) {
114 return n.Blocks.AddBlock(b)
115 }
116
117 +// Get retrieves a node from the DAGService, fetching the block in the BlockService
118 func (n *DAGService) Get(k u.Key) (*Node, error) {
119 if n == nil {
120 return nil, fmt.Errorf("DAGService is nil")
path/path.go
+12 -3
@@ -9,12 +9,15 @@ import (
9 "strings"
10 )
11
12 -// Path resolution for IPFS
13 -
12 +// Resolver provides path resolution to IPFS
13 +// It has a pointer to a DAGService, which is uses to resolve nodes.
14 type Resolver struct {
15 DAG *merkledag.DAGService
16 }
17
18 +// ResolvePath fetches the node for given path. It uses the first
19 +// path component as a hash (key) of the first node, then resolves
20 +// all other components walking the links, with ResolveLinks.
21 func (s *Resolver) ResolvePath(fpath string) (*merkledag.Node, error) {
22 fpath = path.Clean(fpath)
23
@@ -27,7 +30,7 @@ func (s *Resolver) ResolvePath(fpath string) (*merkledag.Node, error) {
30
31 // if nothing, bail.
32 if len(parts) == 0 {
30 - return nil, fmt.Errorf("ipfs path must contain at least one component.")
33 + return nil, fmt.Errorf("ipfs path must contain at least one component")
34 }
35
36 // first element in the path is a b58 hash (for now)
@@ -44,6 +47,12 @@ func (s *Resolver) ResolvePath(fpath string) (*merkledag.Node, error) {
47 return s.ResolveLinks(nd, parts[1:])
48 }
49
50 +// ResolveLinks iteratively resolves names by walking the link hierarchy.
51 +// Every node is fetched from the DAGService, resolving the next name.
52 +// Returns the last node found.
53 +//
54 +// ResolveLinks(nd, []string{"foo", "bar", "baz"})
55 +// would retrieve "baz" in ("bar" in ("foo" in nd.Links).Links).Links
56 func (s *Resolver) ResolveLinks(ndd *merkledag.Node, names []string) (
57 nd *merkledag.Node, err error) {
58
peer/peer.go
+7 -1
@@ -6,24 +6,30 @@ import (
6 mh "github.com/jbenet/go-multihash"
7 )
8
9 +// PeerId is a byte slice representing the identity of a peer.
10 type PeerId mh.Multihash
11
11 -// have to map Key (string) : *Peer because slices are not comparable.
12 +// PeerBook maps Key (string) : *Peer (slices are not comparable).
13 type PeerBook map[u.Key]*Peer
14
15 +// Peer represents the identity information of an IPFS Node, including
16 +// a PeerId, and relevant Addresses.
17 type Peer struct {
18 Id PeerId
19 Addresses []*ma.Multiaddr
20 }
21
22 +// Key returns the PeerId as a Key (string) for maps.
23 func (p *Peer) Key() u.Key {
24 return u.Key(p.Id)
25 }
26
27 +// AddAddress adds the given Multiaddr address to Peer's addresses.
28 func (p *Peer) AddAddress(a *ma.Multiaddr) {
29 p.Addresses = append(p.Addresses, a)
30 }
31
32 +// NetAddress returns the first Multiaddr found for a given network.
33 func (p *Peer) NetAddress(n string) *ma.Multiaddr {
34 for _, a := range p.Addresses {
35 ps, err := a.Protocols()
swarm/conn.go
+6
@@ -9,8 +9,10 @@ import (
9 "net"
10 )
11
12 +// ChanBuffer is the size of the buffer in the Conn Chan
13 const ChanBuffer = 10
14
15 +// Conn represents a connection to another Peer (IPFS Node).
16 type Conn struct {
17 Peer *peer.Peer
18 Addr *ma.Multiaddr
@@ -21,8 +23,11 @@ type Conn struct {
23 Incoming *msgio.Chan
24 }
25
26 +// ConnMap maps Keys (PeerIds) to Connections.
27 type ConnMap map[u.Key]*Conn
28
29 +// Dial connects to a particular peer, over a given network
30 +// Example: Dial("udp", peer)
31 func Dial(network string, peer *peer.Peer) (*Conn, error) {
32 addr := peer.NetAddress(network)
33 if addr == nil {
@@ -58,6 +63,7 @@ func Dial(network string, peer *peer.Peer) (*Conn, error) {
63 return conn, nil
64 }
65
66 +// Close closes the connection, and associated channels.
67 func (s *Conn) Close() error {
68 if s.Conn == nil {
69 return fmt.Errorf("Already closed.") // already closed
swarm/swarm.go
+18
@@ -6,6 +6,8 @@ import (
6 "sync"
7 )
8
9 +// Message represents a packet of information sent to or received from a
10 +// particular Peer.
11 type Message struct {
12 // To or from, depending on direction.
13 Peer *peer.Peer
@@ -14,6 +16,7 @@ type Message struct {
16 Data []byte
17 }
18
19 +// Chan is a swam channel, which provides duplex communication and errors.
20 type Chan struct {
21 Outgoing chan Message
22 Incoming chan Message
@@ -21,6 +24,7 @@ type Chan struct {
24 Close chan bool
25 }
26
27 +// NewChan constructs a Chan instance, with given buffer size bufsize.
28 func NewChan(bufsize int) *Chan {
29 return &Chan{
30 Outgoing: make(chan Message, bufsize),
@@ -30,12 +34,17 @@ func NewChan(bufsize int) *Chan {
34 }
35 }
36
37 +// Swarm is a connection muxer, allowing connections to other peers to
38 +// be opened and closed, while still using the same Chan for all
39 +// communication. The Chan sends/receives Messages, which note the
40 +// destination or source Peer.
41 type Swarm struct {
42 Chan *Chan
43 conns ConnMap
44 connsLock sync.RWMutex
45 }
46
47 +// NewSwarm constructs a Swarm, with a Chan.
48 func NewSwarm() *Swarm {
49 s := &Swarm{
50 Chan: NewChan(10),
@@ -45,6 +54,7 @@ func NewSwarm() *Swarm {
54 return s
55 }
56
57 +// Close closes a swam.
58 func (s *Swarm) Close() {
59 s.connsLock.RLock()
60 l := len(s.conns)
@@ -57,6 +67,14 @@ func (s *Swarm) Close() {
67 s.Chan.Close <- true // listener
68 }
69
70 +// Dial connects to a peer.
71 +//
72 +// The idea is that the client of Swarm does not need to know what network
73 +// the connection will happen over. Swarm can use whichever it choses.
74 +// This allows us to use various transport protocols, do NAT traversal/relay,
75 +// etc. to achive connection.
76 +//
77 +// For now, Dial uses only TCP. This will be extended.
78 func (s *Swarm) Dial(peer *peer.Peer) (*Conn, error) {
79 k := peer.Key()
80
util/util.go
+13 -5
@@ -8,18 +8,21 @@ import (
8 "strings"
9 )
10
11 +// Debug is a global flag for debugging.
12 var Debug bool
12 -var NotImplementedError = fmt.Errorf("Error: not implemented yet.")
13
14 -// a Key for maps. It's a string (rep of a multihash).
14 +// ErrNotImplemented signifies a function has not been implemented yet.
15 +var ErrNotImplemented = fmt.Errorf("Error: not implemented yet.")
16 +
17 +// Key is a string representation of multihash for use with maps.
18 type Key string
19
17 -// global hash function. uses multihash SHA2_256, 256 bits
20 +// Hash is the global IPFS hash function. uses multihash SHA2_256, 256 bits
21 func Hash(data []byte) (mh.Multihash, error) {
22 return mh.Sum(data, mh.SHA2_256, -1)
23 }
24
22 -// tilde expansion
25 +// TildeExpansion expands a filename, which may begin with a tilde.
26 func TildeExpansion(filename string) (string, error) {
27 if strings.HasPrefix(filename, "~/") {
28 usr, err := user.Current()
@@ -33,21 +36,26 @@ func TildeExpansion(filename string) (string, error) {
36 return filename, nil
37 }
38
36 -// Shorthand printing functions.
39 +// PErr is a shorthand printing function to output to Stderr.
40 func PErr(format string, a ...interface{}) {
41 fmt.Fprintf(os.Stderr, format, a...)
42 }
43
44 +// POut is a shorthand printing function to output to Stdout.
45 func POut(format string, a ...interface{}) {
46 fmt.Fprintf(os.Stdout, format, a...)
47 }
48
49 +// DErr is a shorthand debug printing function to output to Stderr.
50 +// Will only print if Debug is true.
51 func DErr(format string, a ...interface{}) {
52 if Debug {
53 PErr(format, a...)
54 }
55 }
56
57 +// DOut is a shorthand debug printing function to output to Stdout.
58 +// Will only print if Debug is true.
59 func DOut(format string, a ...interface{}) {
60 if Debug {
61 POut(format, a...)