Skip to content
Permalink
Browse files

release hive_alpha-v0.1.1

  • Loading branch information...
Yi Wang
Yi Wang committed Jan 13, 2019
1 parent 17599da commit 0d6023a65b1fbd92fc90000943e405d20f248bb8

Large diffs are not rendered by default.

@@ -6,6 +6,7 @@ package client
import (
"context"
"fmt"
"net"
"net/http"
"time"

@@ -221,23 +222,42 @@ func NewDefaultClient(cfg *Config) (Client, error) {
}

func (c *defaultClient) setupAPIAddr() error {
if c.config.APIAddr != nil {
return nil // already setup by user
}

var addr ma.Multiaddr
var err error
if c.config.APIAddr == nil {
if c.config.Host == "" { //default
addr, err = ma.NewMultiaddr(DefaultAPIAddr)
} else {
addrStr := fmt.Sprintf("/dns4/%s/tcp/%s", c.config.Host, c.config.Port)
addr, err = ma.NewMultiaddr(addrStr)
}

if c.config.Host == "" { //default
addr, err := ma.NewMultiaddr(DefaultAPIAddr)
c.config.APIAddr = addr
return err
}

return nil
var addrStr string
ip := net.ParseIP(c.config.Host)
switch {
case ip == nil:
addrStr = fmt.Sprintf("/dns4/%s/tcp/%s", c.config.Host, c.config.Port)
case ip.To4() != nil:
addrStr = fmt.Sprintf("/ip4/%s/tcp/%s", c.config.Host, c.config.Port)
default:
addrStr = fmt.Sprintf("/ip6/%s/tcp/%s", c.config.Host, c.config.Port)
}

addr, err = ma.NewMultiaddr(addrStr)
c.config.APIAddr = addr
return err
}

func (c *defaultClient) resolveAPIAddr() error {
// Only resolve libp2p addresses. For HTTP addresses, we let
// the default client handle any resolving. We extract the hostname
// in setupHostname()
if !IsPeerAddress(c.config.APIAddr) {
return nil
}
resolveCtx, cancel := context.WithTimeout(c.ctx, ResolveTimeout)
defer cancel()
resolved, err := madns.Resolve(resolveCtx, c.config.APIAddr)
@@ -279,13 +299,14 @@ func (c *defaultClient) setupHTTPClient() error {
func (c *defaultClient) setupHostname() error {
// Extract host:port form APIAddr or use Host:Port.
// For libp2p, hostname is set in enableLibp2p()
if !IsPeerAddress(c.config.APIAddr) {
_, hostname, err := manet.DialArgs(c.config.APIAddr)
if err != nil {
return err
}
c.hostname = hostname
if IsPeerAddress(c.config.APIAddr) {
return nil
}
_, hostname, err := manet.DialArgs(c.config.APIAddr)
if err != nil {
return err
}
c.hostname = hostname
return nil
}

@@ -152,23 +152,54 @@ func TestMultiaddressPrecedence(t *testing.T) {
}

func TestHostPort(t *testing.T) {
cfg := &Config{
APIAddr: nil,
Host: "3.3.1.1",
Port: "9094",
DisableKeepAlives: true,
}
c, err := NewDefaultClient(cfg)
if err != nil {
t.Fatal(err)
}
dc := c.(*defaultClient)
if dc.hostname != "3.3.1.1:9094" {
t.Error("Host Port should be used")
}

if dc.config.ProxyAddr == nil || dc.config.ProxyAddr.String() != "/ip4/3.3.1.1/tcp/9095" {
t.Error("proxy address was not guessed correctly")
type testcase struct {
host string
port string
expectedHostname string
expectedProxyAddr string
}

testcases := []testcase{
testcase{
host: "3.3.1.1",
port: "9094",
expectedHostname: "3.3.1.1:9094",
expectedProxyAddr: "/ip4/3.3.1.1/tcp/9095",
},
testcase{
host: "ipfs.io",
port: "9094",
expectedHostname: "ipfs.io:9094",
expectedProxyAddr: "/dns4/ipfs.io/tcp/9095",
},
testcase{
host: "2001:db8::1",
port: "9094",
expectedHostname: "[2001:db8::1]:9094",
expectedProxyAddr: "/ip6/2001:db8::1/tcp/9095",
},
}

for _, tc := range testcases {
cfg := &Config{
APIAddr: nil,
Host: tc.host,
Port: tc.port,
DisableKeepAlives: true,
}
c, err := NewDefaultClient(cfg)
if err != nil {
t.Fatal(err)
}
dc := c.(*defaultClient)
if dc.hostname != tc.expectedHostname {
t.Error("Host Port should be used")
}

if paddr := dc.config.ProxyAddr; paddr == nil || paddr.String() != tc.expectedProxyAddr {
t.Error("proxy address was not guessed correctly: ", paddr)
}
}
}

@@ -185,12 +216,12 @@ func TestDNSMultiaddress(t *testing.T) {
t.Fatal(err)
}
dc := c.(*defaultClient)
if dc.hostname != "127.0.0.1:1234" {
t.Error("bad resolved address")
if dc.hostname != "localhost:1234" {
t.Error("address should not be resolved")
}

if dc.config.ProxyAddr == nil || dc.config.ProxyAddr.String() != "/ip4/127.0.0.1/tcp/9095" {
t.Error("proxy address was not guessed correctly")
if paddr := dc.config.ProxyAddr; paddr == nil || paddr.String() != "/dns4/localhost/tcp/9095" {
t.Error("proxy address was not guessed correctly: ", paddr)
}
}

@@ -12,6 +12,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"mime/multipart"
"regexp"
"sort"
"strings"
@@ -964,3 +965,44 @@ type IPFSRepoStat struct {
RepoSize uint64
StorageMax uint64
}

// UIDSecret wraps node register keys in the Hive Cluster.
type UIDSecret struct {
UID string
PeerID string
}

// UIDLogIn wraps node keys renaming in the Hive Cluster.
type UIDLogIn struct {
UID string
OldUID string
PeerID string
}

// FilesLs wraps files/ls entries in the Hive Cluster.
type FilesLs struct {
Entries []FileLsEntrie
}

type FileLsEntrie struct {
Name string
Type int
Size uint64
Hash string
}

type FilesStat struct {
Hash string
Size uint64
CumulativeSize uint64
Blocks int
Type string
WithLocality bool
Local bool
SizeLocal uint64
}

type FilesWrite struct {
MultipartReader *multipart.Reader
Params []string
}
@@ -20,7 +20,11 @@ func NewClusterHost(ctx context.Context, cfg *Config) (host.Host, error) {
// Create protector if we have a secret.
if cfg.Secret != nil && len(cfg.Secret) > 0 {
var key [32]byte
hiveFlag := []byte("hive.cluster")
copy(key[:], cfg.Secret)
for i := 0; i < len(hiveFlag); i++ {
key[i] ^= hiveFlag[i]
}
prot, err = pnet.NewV1ProtectorFromBytes(&key)
if err != nil {
return nil, err
@@ -308,9 +308,9 @@ configuration.
Name: "upgrade",
Usage: "upgrade the IPFS Cluster state to the current version",
Description: `
This command upgrades the internal state of the ipfs-cluster node
specified in the latest raft snapshot. The state format is migrated from the
version of the snapshot to the version supported by the current cluster version.
This command upgrades the internal state of the ipfs-cluster node
specified in the latest raft snapshot. The state format is migrated from the
version of the snapshot to the version supported by the current cluster version.
To successfully run an upgrade of an entire cluster, shut down each peer without
removal, upgrade state using this command, and restart every peer.
`,
@@ -328,7 +328,7 @@ removal, upgrade state using this command, and restart every peer.
Name: "export",
Usage: "save the IPFS Cluster state to a json file",
Description: `
This command reads the current cluster state and saves it as json for
This command reads the current cluster state and saves it as json for
human readability and editing. Only state formats compatible with this
version of ipfs-cluster-service can be exported. By default this command
prints the state to stdout.
@@ -412,7 +412,7 @@ import. If no argument is provided cluster will read json from stdin
This command removes the persistent state that is loaded on startup to determine this peer's view of the
cluster state. While it removes the existing state from the load path, one invocation does not permanently remove
this state from disk. This command renames cluster's data folder to <data-folder-name>.old.0, and rotates other
deprecated data folders to <data-folder-name>.old.<n+1>, etc for some rotation factor before permanatly deleting
deprecated data folders to <data-folder-name>.old.<n+1>, etc for some rotation factor before permanatly deleting
the mth data folder (m currently defaults to 5)
`,
Flags: []cli.Flag{
@@ -447,7 +447,7 @@ the mth data folder (m currently defaults to 5)
Name: "version",
Usage: "Print the ipfs-cluster version",
Action: func(c *cli.Context) error {
fmt.Printf("%s\n", version.Version)
fmt.Printf("%s+hive.cluster\n", version.Version)
return nil
},
},
@@ -1,6 +1,7 @@
gx_version=v0.14.1
gx-go_version=v1.9.0
gateway=https://ipfs.io
gateway_ipfsboost=https://dist.ipfsboost.com
local_gateway=http://127.0.0.1:8080
dist=dist.ipfs.io
dl_cmd=wget -nc
@@ -17,14 +18,16 @@ gx-go_dist_path=/ipns/$(dist)/gx-go/$(gx-go_version)/$(gx-go_tar)

gx_download_local=$(dl_cmd) $(local_gateway)$(gx_dist_path)
gx_download=$(dl_cmd) $(gateway)$(gx_dist_path)
gx_download_ipfsboost=$(dl_cmd) $(gateway_ipfsboost)$(gx_dist_path)

gx-go_download_local=$(dl_cmd) $(local_gateway)$(gx-go_dist_path)
gx-go_download=$(dl_cmd) $(gateway)$(gx-go_dist_path)
gx-go_download_ipfsboost=$(dl_cmd) $(gateway_ipfsboost)$(gx-go_dist_path)

$(gx):
@echo "Downloading gx"
rm -f gx
$(gx_download_local) || $(gx_download)
$(gx_download_local) || $(gx_download_ipfsboost) || $(gx_download)
tar -zxf $(gx_tar) --strip-components=1 gx/gx
mv gx $(gx)
ln -s $(gx) gx
@@ -33,7 +36,7 @@ $(gx):
$(gx-go):
@echo "Downloading gx-go"
rm -f gx-go
$(gx-go_download_local) || $(gx-go_download)
$(gx-go_download_local) || $(gx-go_download_ipfsboost) || $(gx-go_download)
tar -zxf $(gx-go_tar) --strip-components=1 gx-go/gx-go
mv gx-go $(gx-go)
ln -s $(gx-go) gx-go
@@ -87,6 +87,28 @@ type IPFSConnector interface {
BlockPut(api.NodeWithMeta) error
// BlockGet retrieves the raw data of an IPFS block
BlockGet(cid.Cid) ([]byte, error)
// UidNew registers a uid in hive cluster
UidNew(name string) (api.UIDSecret, error)
// UidLogIn is used to change uid
UidLogIn([]string) (api.UIDLogIn, error)
// FilesCp is used to copy file
FilesCp([]string) error
// FilesFlush is used to change uid
FilesFlush([]string) error
// FilesLs is used to list files
FilesLs([]string) (api.FilesLs, error)
// FilesMkdir creates directory in IFPS peer
FilesMkdir([]string) error
// FilesMv moves file in IPFS peer
FilesMv([]string) error
// FilesRead reads file
FilesRead([]string) ([]byte, error)
// FilesRm remove directory from IPFS peer
FilesRm([]string) error
// FilesStat fetchs file statistics
FilesStat([]string) (api.FilesStat, error)
// FilesWrite writes file
FilesWrite(api.FilesWrite) error
}

// Peered represents a component which needs to be aware of the peers

0 comments on commit 0d6023a

Please sign in to comment.
You can’t perform that action at this time.