mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
swarm: wip golint warnings and cmd
This commit is contained in:
parent
a3a97531e8
commit
2158dbc10a
28 changed files with 92 additions and 92 deletions
|
|
@ -168,7 +168,7 @@ func cmdLineOverride(currentConfig *bzzapi.Config, ctx *cli.Context) *bzzapi.Con
|
||||||
|
|
||||||
if networkid := ctx.GlobalString(SwarmNetworkIdFlag.Name); networkid != "" {
|
if networkid := ctx.GlobalString(SwarmNetworkIdFlag.Name); networkid != "" {
|
||||||
if id, _ := strconv.Atoi(networkid); id != 0 {
|
if id, _ := strconv.Atoi(networkid); id != 0 {
|
||||||
currentConfig.NetworkId = uint64(id)
|
currentConfig.NetworkID = uint64(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -195,8 +195,8 @@ func cmdLineOverride(currentConfig *bzzapi.Config, ctx *cli.Context) *bzzapi.Con
|
||||||
currentConfig.SyncEnabled = true
|
currentConfig.SyncEnabled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
currentConfig.SwapApi = ctx.GlobalString(SwarmSwapAPIFlag.Name)
|
currentConfig.SwapAPI = ctx.GlobalString(SwarmSwapAPIFlag.Name)
|
||||||
if currentConfig.SwapEnabled && currentConfig.SwapApi == "" {
|
if currentConfig.SwapEnabled && currentConfig.SwapAPI == "" {
|
||||||
utils.Fatalf(SWARM_ERR_SWAP_SET_NO_API)
|
utils.Fatalf(SWARM_ERR_SWAP_SET_NO_API)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -239,7 +239,7 @@ func envVarsOverride(currentConfig *bzzapi.Config) (config *bzzapi.Config) {
|
||||||
|
|
||||||
if networkid := os.Getenv(SWARM_ENV_NETWORK_ID); networkid != "" {
|
if networkid := os.Getenv(SWARM_ENV_NETWORK_ID); networkid != "" {
|
||||||
if id, _ := strconv.Atoi(networkid); id != 0 {
|
if id, _ := strconv.Atoi(networkid); id != 0 {
|
||||||
currentConfig.NetworkId = uint64(id)
|
currentConfig.NetworkID = uint64(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -269,10 +269,10 @@ func envVarsOverride(currentConfig *bzzapi.Config) (config *bzzapi.Config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if swapapi := os.Getenv(SWARM_ENV_SWAP_API); swapapi != "" {
|
if swapapi := os.Getenv(SWARM_ENV_SWAP_API); swapapi != "" {
|
||||||
currentConfig.SwapApi = swapapi
|
currentConfig.SwapAPI = swapapi
|
||||||
}
|
}
|
||||||
|
|
||||||
if currentConfig.SwapEnabled && currentConfig.SwapApi == "" {
|
if currentConfig.SwapEnabled && currentConfig.SwapAPI == "" {
|
||||||
utils.Fatalf(SWARM_ERR_SWAP_SET_NO_API)
|
utils.Fatalf(SWARM_ERR_SWAP_SET_NO_API)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -120,8 +120,8 @@ func TestCmdLineOverrides(t *testing.T) {
|
||||||
t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port)
|
t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port)
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.NetworkId != 42 {
|
if info.NetworkID != 42 {
|
||||||
t.Fatalf("Expected network ID to be %d, got %d", 42, info.NetworkId)
|
t.Fatalf("Expected network ID to be %d, got %d", 42, info.NetworkID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !info.SyncEnabled {
|
if !info.SyncEnabled {
|
||||||
|
|
@ -148,7 +148,7 @@ func TestFileOverrides(t *testing.T) {
|
||||||
defaultConf := api.NewDefaultConfig()
|
defaultConf := api.NewDefaultConfig()
|
||||||
//change some values in order to test if they have been loaded
|
//change some values in order to test if they have been loaded
|
||||||
defaultConf.SyncEnabled = true
|
defaultConf.SyncEnabled = true
|
||||||
defaultConf.NetworkId = 54
|
defaultConf.NetworkID = 54
|
||||||
defaultConf.Port = httpPort
|
defaultConf.Port = httpPort
|
||||||
defaultConf.StoreParams.DbCapacity = 9000000
|
defaultConf.StoreParams.DbCapacity = 9000000
|
||||||
defaultConf.ChunkerParams.Branches = 64
|
defaultConf.ChunkerParams.Branches = 64
|
||||||
|
|
@ -215,8 +215,8 @@ func TestFileOverrides(t *testing.T) {
|
||||||
t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port)
|
t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port)
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.NetworkId != 54 {
|
if info.NetworkID != 54 {
|
||||||
t.Fatalf("Expected network ID to be %d, got %d", 54, info.NetworkId)
|
t.Fatalf("Expected network ID to be %d, got %d", 54, info.NetworkID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !info.SyncEnabled {
|
if !info.SyncEnabled {
|
||||||
|
|
@ -224,7 +224,7 @@ func TestFileOverrides(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.StoreParams.DbCapacity != 9000000 {
|
if info.StoreParams.DbCapacity != 9000000 {
|
||||||
t.Fatalf("Expected network ID to be %d, got %d", 54, info.NetworkId)
|
t.Fatalf("Expected network ID to be %d, got %d", 54, info.NetworkID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.ChunkerParams.Branches != 64 {
|
if info.ChunkerParams.Branches != 64 {
|
||||||
|
|
@ -326,8 +326,8 @@ func TestEnvVars(t *testing.T) {
|
||||||
t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port)
|
t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port)
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.NetworkId != 999 {
|
if info.NetworkID != 999 {
|
||||||
t.Fatalf("Expected network ID to be %d, got %d", 999, info.NetworkId)
|
t.Fatalf("Expected network ID to be %d, got %d", 999, info.NetworkID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.Cors != "*" {
|
if info.Cors != "*" {
|
||||||
|
|
@ -355,7 +355,7 @@ func TestCmdLineOverridesFile(t *testing.T) {
|
||||||
defaultConf := api.NewDefaultConfig()
|
defaultConf := api.NewDefaultConfig()
|
||||||
//change some values in order to test if they have been loaded
|
//change some values in order to test if they have been loaded
|
||||||
defaultConf.SyncEnabled = false
|
defaultConf.SyncEnabled = false
|
||||||
defaultConf.NetworkId = 54
|
defaultConf.NetworkID = 54
|
||||||
defaultConf.Port = "8588"
|
defaultConf.Port = "8588"
|
||||||
defaultConf.StoreParams.DbCapacity = 9000000
|
defaultConf.StoreParams.DbCapacity = 9000000
|
||||||
defaultConf.ChunkerParams.Branches = 64
|
defaultConf.ChunkerParams.Branches = 64
|
||||||
|
|
@ -427,8 +427,8 @@ func TestCmdLineOverridesFile(t *testing.T) {
|
||||||
t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port)
|
t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port)
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.NetworkId != expectNetworkId {
|
if info.NetworkID != expectNetworkId {
|
||||||
t.Fatalf("Expected network ID to be %d, got %d", expectNetworkId, info.NetworkId)
|
t.Fatalf("Expected network ID to be %d, got %d", expectNetworkId, info.NetworkID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !info.SyncEnabled {
|
if !info.SyncEnabled {
|
||||||
|
|
@ -436,7 +436,7 @@ func TestCmdLineOverridesFile(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.StoreParams.DbCapacity != 9000000 {
|
if info.StoreParams.DbCapacity != 9000000 {
|
||||||
t.Fatalf("Expected network ID to be %d, got %d", 54, info.NetworkId)
|
t.Fatalf("Expected network ID to be %d, got %d", 54, info.NetworkID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.ChunkerParams.Branches != 64 {
|
if info.ChunkerParams.Branches != 64 {
|
||||||
|
|
|
||||||
|
|
@ -439,7 +439,7 @@ func bzzd(ctx *cli.Context) error {
|
||||||
bootnodes := strings.Split(bzzconfig.BootNodes, ",")
|
bootnodes := strings.Split(bzzconfig.BootNodes, ",")
|
||||||
injectBootnodes(stack.Server(), bootnodes)
|
injectBootnodes(stack.Server(), bootnodes)
|
||||||
} else {
|
} else {
|
||||||
if bzzconfig.NetworkId == 3 {
|
if bzzconfig.NetworkID == 3 {
|
||||||
injectBootnodes(stack.Server(), testbetBootNodes)
|
injectBootnodes(stack.Server(), testbetBootNodes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -454,11 +454,11 @@ func registerBzzService(bzzconfig *bzzapi.Config, ctx *cli.Context, stack *node.
|
||||||
boot := func(ctx *node.ServiceContext) (node.Service, error) {
|
boot := func(ctx *node.ServiceContext) (node.Service, error) {
|
||||||
var swapClient *ethclient.Client
|
var swapClient *ethclient.Client
|
||||||
var err error
|
var err error
|
||||||
if bzzconfig.SwapApi != "" {
|
if bzzconfig.SwapAPI != "" {
|
||||||
log.Info("connecting to SWAP API", "url", bzzconfig.SwapApi)
|
log.Info("connecting to SWAP API", "url", bzzconfig.SwapAPI)
|
||||||
swapClient, err = ethclient.Dial(bzzconfig.SwapApi)
|
swapClient, err = ethclient.Dial(bzzconfig.SwapAPI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error connecting to SWAP API %s: %s", bzzconfig.SwapApi, err)
|
return nil, fmt.Errorf("error connecting to SWAP API %s: %s", bzzconfig.SwapAPI, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/swarm/storage"
|
"github.com/ethereum/go-ethereum/swarm/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testAPI(t *testing.T, f func(*Api)) {
|
func testAPI(t *testing.T, f func(*API)) {
|
||||||
datadir, err := ioutil.TempDir("", "bzz-test")
|
datadir, err := ioutil.TempDir("", "bzz-test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create temp dir: %v", err)
|
t.Fatalf("unable to create temp dir: %v", err)
|
||||||
|
|
@ -40,7 +40,7 @@ func testAPI(t *testing.T, f func(*Api)) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
api := NewApi(dpa, nil)
|
api := NewAPI(dpa, nil)
|
||||||
dpa.Start()
|
dpa.Start()
|
||||||
f(api)
|
f(api)
|
||||||
dpa.Stop()
|
dpa.Stop()
|
||||||
|
|
@ -82,8 +82,8 @@ func expResponse(content string, mimeType string, status int) *Response {
|
||||||
return &Response{mimeType, status, int64(len(content)), content}
|
return &Response{mimeType, status, int64(len(content)), content}
|
||||||
}
|
}
|
||||||
|
|
||||||
// func testGet(t *testing.T, api *Api, bzzhash string) *testResponse {
|
// func testGet(t *testing.T, api *API, bzzhash string) *testResponse {
|
||||||
func testGet(t *testing.T, api *Api, bzzhash, path string) *testResponse {
|
func testGet(t *testing.T, api *API, bzzhash, path string) *testResponse {
|
||||||
key := storage.Key(common.Hex2Bytes(bzzhash))
|
key := storage.Key(common.Hex2Bytes(bzzhash))
|
||||||
reader, mimeType, status, err := api.Get(key, path)
|
reader, mimeType, status, err := api.Get(key, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -106,7 +106,7 @@ func testGet(t *testing.T, api *Api, bzzhash, path string) *testResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestApiPut(t *testing.T) {
|
func TestApiPut(t *testing.T) {
|
||||||
testAPI(t, func(api *Api) {
|
testAPI(t, func(api *API) {
|
||||||
content := "hello"
|
content := "hello"
|
||||||
exp := expResponse(content, "text/plain", 0)
|
exp := expResponse(content, "text/plain", 0)
|
||||||
// exp := expResponse([]byte(content), "text/plain", 0)
|
// exp := expResponse([]byte(content), "text/plain", 0)
|
||||||
|
|
@ -213,7 +213,7 @@ func TestAPIResolve(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, x := range tests {
|
for _, x := range tests {
|
||||||
t.Run(x.desc, func(t *testing.T) {
|
t.Run(x.desc, func(t *testing.T) {
|
||||||
api := &Api{dns: x.dns}
|
api := &API{dns: x.dns}
|
||||||
uri := &URI{Addr: x.addr, Scheme: "bzz"}
|
uri := &URI{Addr: x.addr, Scheme: "bzz"}
|
||||||
if x.immutable {
|
if x.immutable {
|
||||||
uri.Scheme = "bzz-immutable"
|
uri.Scheme = "bzz-immutable"
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,10 @@ import (
|
||||||
const maxParallelFiles = 5
|
const maxParallelFiles = 5
|
||||||
|
|
||||||
type FileSystem struct {
|
type FileSystem struct {
|
||||||
api *Api
|
api *API
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFileSystem(api *Api) *FileSystem {
|
func NewFileSystem(api *API) *FileSystem {
|
||||||
return &FileSystem{api}
|
return &FileSystem{api}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ import (
|
||||||
var testDownloadDir, _ = ioutil.TempDir(os.TempDir(), "bzz-test")
|
var testDownloadDir, _ = ioutil.TempDir(os.TempDir(), "bzz-test")
|
||||||
|
|
||||||
func testFileSystem(t *testing.T, f func(*FileSystem)) {
|
func testFileSystem(t *testing.T, f func(*FileSystem)) {
|
||||||
testApi(t, func(api *Api) {
|
testAPI(t, func(api *API) {
|
||||||
f(NewFileSystem(api))
|
f(NewFileSystem(api))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ type ServerConfig struct {
|
||||||
// https://github.com/atom/electron/blob/master/docs/api/protocol.md
|
// https://github.com/atom/electron/blob/master/docs/api/protocol.md
|
||||||
|
|
||||||
// StartHTTPServer starts up http server
|
// StartHTTPServer starts up http server
|
||||||
func StartHTTPServer(api *api.Api, config *ServerConfig) {
|
func StartHTTPServer(api *api.API, config *ServerConfig) {
|
||||||
var allowedOrigins []string
|
var allowedOrigins []string
|
||||||
for _, domain := range strings.Split(config.CorsString, ",") {
|
for _, domain := range strings.Split(config.CorsString, ",") {
|
||||||
allowedOrigins = append(allowedOrigins, strings.TrimSpace(domain))
|
allowedOrigins = append(allowedOrigins, strings.TrimSpace(domain))
|
||||||
|
|
@ -95,12 +95,12 @@ func StartHTTPServer(api *api.Api, config *ServerConfig) {
|
||||||
go http.ListenAndServe(config.Addr, hdlr)
|
go http.ListenAndServe(config.Addr, hdlr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer(api *api.Api) *Server {
|
func NewServer(api *api.API) *Server {
|
||||||
return &Server{api}
|
return &Server{api}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
api *api.Api
|
api *api.API
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request wraps http.Request and also includes the parsed bzz URI
|
// Request wraps http.Request and also includes the parsed bzz URI
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ type ManifestList struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewManifest creates and stores a new, empty manifest
|
// NewManifest creates and stores a new, empty manifest
|
||||||
func (a *Api) NewManifest() (storage.Key, error) {
|
func (a *API) NewManifest() (storage.Key, error) {
|
||||||
var manifest Manifest
|
var manifest Manifest
|
||||||
data, err := json.Marshal(&manifest)
|
data, err := json.Marshal(&manifest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -70,12 +70,12 @@ func (a *Api) NewManifest() (storage.Key, error) {
|
||||||
|
|
||||||
// ManifestWriter is used to add and remove entries from an underlying manifest
|
// ManifestWriter is used to add and remove entries from an underlying manifest
|
||||||
type ManifestWriter struct {
|
type ManifestWriter struct {
|
||||||
api *Api
|
api *API
|
||||||
trie *manifestTrie
|
trie *manifestTrie
|
||||||
quitC chan bool
|
quitC chan bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Api) NewManifestWriter(key storage.Key, quitC chan bool) (*ManifestWriter, error) {
|
func (a *API) NewManifestWriter(key storage.Key, quitC chan bool) (*ManifestWriter, error) {
|
||||||
trie, err := loadManifest(a.dpa, key, quitC)
|
trie, err := loadManifest(a.dpa, key, quitC)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error loading manifest %s: %s", key, err)
|
return nil, fmt.Errorf("error loading manifest %s: %s", key, err)
|
||||||
|
|
@ -109,12 +109,12 @@ func (m *ManifestWriter) Store() (storage.Key, error) {
|
||||||
// ManifestWalker is used to recursively walk the entries in the manifest and
|
// ManifestWalker is used to recursively walk the entries in the manifest and
|
||||||
// all of its submanifests
|
// all of its submanifests
|
||||||
type ManifestWalker struct {
|
type ManifestWalker struct {
|
||||||
api *Api
|
api *API
|
||||||
trie *manifestTrie
|
trie *manifestTrie
|
||||||
quitC chan bool
|
quitC chan bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Api) NewManifestWalker(key storage.Key, quitC chan bool) (*ManifestWalker, error) {
|
func (a *API) NewManifestWalker(key storage.Key, quitC chan bool) (*ManifestWalker, error) {
|
||||||
trie, err := loadManifest(a.dpa, key, quitC)
|
trie, err := loadManifest(a.dpa, key, quitC)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error loading manifest %s: %s", key, err)
|
return nil, fmt.Errorf("error loading manifest %s: %s", key, err)
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,10 @@ type Response struct {
|
||||||
//
|
//
|
||||||
// DEPRECATED: Use the HTTP API instead
|
// DEPRECATED: Use the HTTP API instead
|
||||||
type Storage struct {
|
type Storage struct {
|
||||||
api *Api
|
api *API
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStorage(api *Api) *Storage {
|
func NewStorage(api *API) *Storage {
|
||||||
return &Storage{api}
|
return &Storage{api}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func testStorage(t *testing.T, f func(*Storage)) {
|
func testStorage(t *testing.T, f func(*Storage)) {
|
||||||
testApi(t, func(api *Api) {
|
testAPI(t, func(api *API) {
|
||||||
f(NewStorage(api))
|
f(NewStorage(api))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Control struct {
|
type Control struct {
|
||||||
api *Api
|
api *API
|
||||||
hive *network.Hive
|
hive *network.Hive
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewControl(api *Api, hive *network.Hive) *Control {
|
func NewControl(api *API, hive *network.Hive) *Control {
|
||||||
return &Control{api, hive}
|
return &Control{api, hive}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,12 +39,12 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type SwarmFS struct {
|
type SwarmFS struct {
|
||||||
swarmAPI *api.Api
|
swarmAPI *api.API
|
||||||
activeMounts map[string]*MountInfo
|
activeMounts map[string]*MountInfo
|
||||||
swarmFsLock *sync.RWMutex
|
swarmFsLock *sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSwarmFS(api *api.Api) *SwarmFS {
|
func NewSwarmFS(api *api.API) *SwarmFS {
|
||||||
swarmfsLock.Do(func() {
|
swarmfsLock.Do(func() {
|
||||||
swarmfs = &SwarmFS{
|
swarmfs = &SwarmFS{
|
||||||
swarmAPI: api,
|
swarmAPI: api,
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ type fileInfo struct {
|
||||||
contents []byte
|
contents []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTestFilesAndUploadToSwarm(t *testing.T, api *api.Api, files map[string]fileInfo, uploadDir string) string {
|
func createTestFilesAndUploadToSwarm(t *testing.T, api *api.API, files map[string]fileInfo, uploadDir string) string {
|
||||||
os.RemoveAll(uploadDir)
|
os.RemoveAll(uploadDir)
|
||||||
|
|
||||||
for fname, finfo := range files {
|
for fname, finfo := range files {
|
||||||
|
|
@ -70,7 +70,7 @@ func createTestFilesAndUploadToSwarm(t *testing.T, api *api.Api, files map[strin
|
||||||
return bzzhash
|
return bzzhash
|
||||||
}
|
}
|
||||||
|
|
||||||
func mountDir(t *testing.T, api *api.Api, files map[string]fileInfo, bzzHash string, mountDir string) *SwarmFS {
|
func mountDir(t *testing.T, api *api.API, files map[string]fileInfo, bzzHash string, mountDir string) *SwarmFS {
|
||||||
os.RemoveAll(mountDir)
|
os.RemoveAll(mountDir)
|
||||||
os.MkdirAll(mountDir, 0777)
|
os.MkdirAll(mountDir, 0777)
|
||||||
swarmfs := NewSwarmFS(api)
|
swarmfs := NewSwarmFS(api)
|
||||||
|
|
@ -190,7 +190,7 @@ func isDirEmpty(name string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
type testAPI struct {
|
type testAPI struct {
|
||||||
api *api.Api
|
api *api.API
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ta *testAPI) mountListAndUnmount(t *testing.T) {
|
func (ta *testAPI) mountListAndUnmount(t *testing.T) {
|
||||||
|
|
@ -812,7 +812,7 @@ func TestFUSE(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
ta := &testAPI{api: api.NewApi(dpa, nil)}
|
ta := &testAPI{api: api.NewAPI(dpa, nil)}
|
||||||
dpa.Start()
|
dpa.Start()
|
||||||
defer dpa.Stop()
|
defer dpa.Stop()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,11 +55,11 @@ type MountInfo struct {
|
||||||
LatestManifest string
|
LatestManifest string
|
||||||
rootDir *SwarmDir
|
rootDir *SwarmDir
|
||||||
fuseConnection *fuse.Conn
|
fuseConnection *fuse.Conn
|
||||||
swarmAPI *api.Api
|
swarmAPI *api.API
|
||||||
lock *sync.RWMutex
|
lock *sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMountInfo(mhash, mpoint string, sapi *api.Api) *MountInfo {
|
func NewMountInfo(mhash, mpoint string, sapi *api.API) *MountInfo {
|
||||||
newMountInfo := &MountInfo{
|
newMountInfo := &MountInfo{
|
||||||
MountPoint: mpoint,
|
MountPoint: mpoint,
|
||||||
StartManifest: mhash,
|
StartManifest: mhash,
|
||||||
|
|
|
||||||
|
|
@ -177,7 +177,7 @@ func (d *Depo) HandleRetrieveRequestMsg(req *retrieveRequestMsgData, p *peer) {
|
||||||
|
|
||||||
if req.MaxSize == 0 || int64(req.MaxSize) >= chunk.Size {
|
if req.MaxSize == 0 || int64(req.MaxSize) >= chunk.Size {
|
||||||
sreq := &storeRequestMsgData{
|
sreq := &storeRequestMsgData{
|
||||||
Id: req.Id,
|
ID: req.ID,
|
||||||
Key: chunk.Key,
|
Key: chunk.Key,
|
||||||
SData: chunk.SData,
|
SData: chunk.SData,
|
||||||
requestTimeout: req.timeout, //
|
requestTimeout: req.timeout, //
|
||||||
|
|
@ -223,7 +223,7 @@ only add if less than requesterCount peers forwarded the same request id so far
|
||||||
note this is done irrespective of status (searching or found)
|
note this is done irrespective of status (searching or found)
|
||||||
*/
|
*/
|
||||||
func (d *Depo) addRequester(rs *storage.RequestStatus, req *retrieveRequestMsgData) {
|
func (d *Depo) addRequester(rs *storage.RequestStatus, req *retrieveRequestMsgData) {
|
||||||
log.Trace(fmt.Sprintf("Depo.addRequester: key %v - add peer to req.Id %v", req.Key.Log(), req.Id))
|
log.Trace(fmt.Sprintf("Depo.addRequester: key %v - add peer to req.ID %v", req.Key.Log(), req.ID))
|
||||||
list := rs.Requesters[req.Id]
|
list := rs.Requesters[req.ID]
|
||||||
rs.Requesters[req.Id] = append(list, req)
|
rs.Requesters[req.ID] = append(list, req)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ OUT:
|
||||||
}
|
}
|
||||||
req := &retrieveRequestMsgData{
|
req := &retrieveRequestMsgData{
|
||||||
Key: chunk.Key,
|
Key: chunk.Key,
|
||||||
Id: generateID(),
|
ID: generateID(),
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
if p.swap != nil {
|
if p.swap != nil {
|
||||||
|
|
@ -123,8 +123,8 @@ func (f *forwarder) Deliver(chunk *storage.Chunk) {
|
||||||
for id, r := range requesters {
|
for id, r := range requesters {
|
||||||
req = r.(*retrieveRequestMsgData)
|
req = r.(*retrieveRequestMsgData)
|
||||||
if req.timeout == nil || req.timeout.After(time.Now()) {
|
if req.timeout == nil || req.timeout.After(time.Now()) {
|
||||||
log.Trace(fmt.Sprintf("forwarder.Deliver: %v -> %v", req.Id, req.from))
|
log.Trace(fmt.Sprintf("forwarder.Deliver: %v -> %v", req.ID, req.from))
|
||||||
msg.Id = uint64(id)
|
msg.ID = uint64(id)
|
||||||
Deliver(req.from, msg, DeliverReq)
|
Deliver(req.from, msg, DeliverReq)
|
||||||
n++
|
n++
|
||||||
counter--
|
counter--
|
||||||
|
|
|
||||||
|
|
@ -386,12 +386,12 @@ func (h *Hive) peers(req *retrieveRequestMsgData) {
|
||||||
for _, peer := range h.getPeers(key, int(req.MaxPeers)) {
|
for _, peer := range h.getPeers(key, int(req.MaxPeers)) {
|
||||||
addrs = append(addrs, peer.remoteAddr)
|
addrs = append(addrs, peer.remoteAddr)
|
||||||
}
|
}
|
||||||
log.Debug(fmt.Sprintf("Hive sending %d peer addresses to %v. req.Id: %v, req.Key: %v", len(addrs), req.from, req.Id, req.Key.Log()))
|
log.Debug(fmt.Sprintf("Hive sending %d peer addresses to %v. req.ID: %v, req.Key: %v", len(addrs), req.from, req.ID, req.Key.Log()))
|
||||||
|
|
||||||
peersData := &peersMsgData{
|
peersData := &peersMsgData{
|
||||||
Peers: addrs,
|
Peers: addrs,
|
||||||
Key: req.Key,
|
Key: req.Key,
|
||||||
Id: req.Id,
|
ID: req.ID,
|
||||||
}
|
}
|
||||||
peersData.setTimeout(req.timeout)
|
peersData.setTimeout(req.timeout)
|
||||||
req.from.peers(peersData)
|
req.from.peers(peersData)
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ type Kademlia struct {
|
||||||
|
|
||||||
type Node interface {
|
type Node interface {
|
||||||
Addr() Address
|
Addr() Address
|
||||||
Url() string
|
URL() string
|
||||||
LastActive() time.Time
|
LastActive() time.Time
|
||||||
Drop()
|
Drop()
|
||||||
}
|
}
|
||||||
|
|
@ -132,7 +132,7 @@ func (k *Kademlia) On(node Node, cb func(*NodeRecord, Node) error) (err error) {
|
||||||
k.lock.Lock()
|
k.lock.Lock()
|
||||||
|
|
||||||
index := k.proximityBin(node.Addr())
|
index := k.proximityBin(node.Addr())
|
||||||
record := k.db.findOrCreate(index, node.Addr(), node.Url())
|
record := k.db.findOrCreate(index, node.Addr(), node.URL())
|
||||||
|
|
||||||
if cb != nil {
|
if cb != nil {
|
||||||
err = cb(record, node)
|
err = cb(record, node)
|
||||||
|
|
|
||||||
|
|
@ -330,7 +330,7 @@ func (b *bzz) handleStatus() (err error) {
|
||||||
handshake := &statusMsgData{
|
handshake := &statusMsgData{
|
||||||
Version: uint64(Version),
|
Version: uint64(Version),
|
||||||
ID: "honey",
|
ID: "honey",
|
||||||
Addr: b.bAddr(),
|
Addr: b.selfAddr(),
|
||||||
NetworkID: b.NetworkID,
|
NetworkID: b.NetworkID,
|
||||||
Swap: &bzzswap.SwapProfile{
|
Swap: &bzzswap.SwapProfile{
|
||||||
Profile: b.swapParams.Profile,
|
Profile: b.swapParams.Profile,
|
||||||
|
|
@ -374,7 +374,7 @@ func (b *bzz) handleStatus() (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
b.remoteAddr = b.peerAddr(status.Addr)
|
b.remoteAddr = b.peerAddr(status.Addr)
|
||||||
log.Trace(fmt.Sprintf("b: advertised IP: %v, peer advertised: %v, local address: %v\npeer: advertised IP: %v, remote address: %v\n", b.bAddr(), b.remoteAddr, b.peer.LocalAddr(), status.Addr.IP, b.peer.RemoteAddr()))
|
log.Trace(fmt.Sprintf("b: advertised IP: %v, peer advertised: %v, local address: %v\npeer: advertised IP: %v, remote address: %v\n", b.selfAddr(), b.remoteAddr, b.peer.LocalAddr(), status.Addr.IP, b.peer.RemoteAddr()))
|
||||||
|
|
||||||
if b.swapEnabled {
|
if b.swapEnabled {
|
||||||
// set remote profile for accounting
|
// set remote profile for accounting
|
||||||
|
|
@ -410,7 +410,7 @@ func (b *bzz) sync(state *syncState) error {
|
||||||
// an explicitly received nil syncstate disables syncronisation
|
// an explicitly received nil syncstate disables syncronisation
|
||||||
if state == nil {
|
if state == nil {
|
||||||
b.syncEnabled = false
|
b.syncEnabled = false
|
||||||
log.Warn(fmt.Sprintf("syncronisation disabled for peer %v", n))
|
log.Warn(fmt.Sprintf("syncronisation disabled for peer %v", b))
|
||||||
state = &syncState{DbSyncState: &storage.DbSyncState{}, Synced: true}
|
state = &syncState{DbSyncState: &storage.DbSyncState{}, Synced: true}
|
||||||
} else {
|
} else {
|
||||||
state.synced = make(chan bool)
|
state.synced = make(chan bool)
|
||||||
|
|
@ -419,7 +419,7 @@ func (b *bzz) sync(state *syncState) error {
|
||||||
state.Start = storage.Key(start[:])
|
state.Start = storage.Key(start[:])
|
||||||
state.Stop = storage.Key(stop[:])
|
state.Stop = storage.Key(stop[:])
|
||||||
}
|
}
|
||||||
log.Debug(fmt.Sprintf("syncronisation requested by peer %v at state %v", n, state))
|
log.Debug(fmt.Sprintf("syncronisation requested by peer %v at state %v", b, state))
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
b.syncer, err = newSyncer(
|
b.syncer, err = newSyncer(
|
||||||
|
|
@ -432,7 +432,7 @@ func (b *bzz) sync(state *syncState) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
log.Trace(fmt.Sprintf("syncer set for peer %v", n))
|
log.Trace(fmt.Sprintf("syncer set for peer %v", b))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -358,13 +358,13 @@ func (d *syncDb) newSyncDbEntry(req interface{}, counter uint64) (entry *syncDbE
|
||||||
var sreq *storeRequestMsgData
|
var sreq *storeRequestMsgData
|
||||||
|
|
||||||
if key, ok = req.(storage.Key); ok {
|
if key, ok = req.(storage.Key); ok {
|
||||||
id = generateId()
|
id = generateID()
|
||||||
} else if chunk, ok = req.(*storage.Chunk); ok {
|
} else if chunk, ok = req.(*storage.Chunk); ok {
|
||||||
key = chunk.Key
|
key = chunk.Key
|
||||||
id = generateId()
|
id = generateID()
|
||||||
} else if sreq, ok = req.(*storeRequestMsgData); ok {
|
} else if sreq, ok = req.(*storeRequestMsgData); ok {
|
||||||
key = sreq.Key
|
key = sreq.Key
|
||||||
id = sreq.Id
|
id = sreq.ID
|
||||||
} else if entry, ok = req.(*syncDbEntry); !ok {
|
} else if entry, ok = req.(*syncDbEntry); !ok {
|
||||||
return nil, fmt.Errorf("type not allowed: %v (%T)", req, req)
|
return nil, fmt.Errorf("type not allowed: %v (%T)", req, req)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -738,7 +738,7 @@ func (s *syncer) newStoreRequestMsgData(req interface{}) (*storeRequestMsgData,
|
||||||
}
|
}
|
||||||
|
|
||||||
sreq = &storeRequestMsgData{
|
sreq = &storeRequestMsgData{
|
||||||
Id: id,
|
ID: id,
|
||||||
Key: chunk.Key,
|
Key: chunk.Key,
|
||||||
SData: chunk.SData,
|
SData: chunk.SData,
|
||||||
}
|
}
|
||||||
|
|
@ -759,7 +759,7 @@ func parseRequest(req interface{}) (storage.Key, uint64, *storage.Chunk, *storeR
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if key, ok = req.(storage.Key); ok {
|
if key, ok = req.(storage.Key); ok {
|
||||||
id = generateId()
|
id = generateID()
|
||||||
|
|
||||||
} else if entry, ok = req.(*syncDbEntry); ok {
|
} else if entry, ok = req.(*syncDbEntry); ok {
|
||||||
id = binary.BigEndian.Uint64(entry.val[32:])
|
id = binary.BigEndian.Uint64(entry.val[32:])
|
||||||
|
|
@ -767,7 +767,7 @@ func parseRequest(req interface{}) (storage.Key, uint64, *storage.Chunk, *storeR
|
||||||
|
|
||||||
} else if chunk, ok = req.(*storage.Chunk); ok {
|
} else if chunk, ok = req.(*storage.Chunk); ok {
|
||||||
key = chunk.Key
|
key = chunk.Key
|
||||||
id = generateId()
|
id = generateID()
|
||||||
|
|
||||||
} else if sreq, ok = req.(*storeRequestMsgData); ok {
|
} else if sreq, ok = req.(*storeRequestMsgData); ok {
|
||||||
key = sreq.Key
|
key = sreq.Key
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ func testStore(m ChunkStore, l int64, branches int64, t *testing.T) {
|
||||||
for ch := range chunkC {
|
for ch := range chunkC {
|
||||||
go func(chunk *Chunk) {
|
go func(chunk *Chunk) {
|
||||||
storedChunk, err := m.Get(chunk.Key)
|
storedChunk, err := m.Get(chunk.Key)
|
||||||
if err == notFound {
|
if err == errNotFound {
|
||||||
log.Trace(fmt.Sprintf("chunk '%v' not found", chunk.Key.Log()))
|
log.Trace(fmt.Sprintf("chunk '%v' not found", chunk.Key.Log()))
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
log.Trace(fmt.Sprintf("error retrieving chunk %v: %v", chunk.Key.Log(), err))
|
log.Trace(fmt.Sprintf("error retrieving chunk %v: %v", chunk.Key.Log(), err))
|
||||||
|
|
|
||||||
|
|
@ -495,7 +495,7 @@ func (s *DbStore) Get(key Key) (chunk *Chunk, err error) {
|
||||||
}
|
}
|
||||||
decodeData(data, chunk)
|
decodeData(data, chunk)
|
||||||
} else {
|
} else {
|
||||||
err = notFound
|
err = errNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -66,8 +66,8 @@ func TestDbStoreNotFound(t *testing.T) {
|
||||||
m := initDbStore(t)
|
m := initDbStore(t)
|
||||||
defer m.Close()
|
defer m.Close()
|
||||||
_, err := m.Get(ZeroKey)
|
_, err := m.Get(ZeroKey)
|
||||||
if err != notFound {
|
if err != errNotFound {
|
||||||
t.Errorf("Expected notFound, got %v", err)
|
t.Errorf("Expected errNotFound, got %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,7 @@ func (s *MemStore) Get(hash Key) (chunk *Chunk, err error) {
|
||||||
l := hash.bits(bitpos, node.bits)
|
l := hash.bits(bitpos, node.bits)
|
||||||
st := node.subtree[l]
|
st := node.subtree[l]
|
||||||
if st == nil {
|
if st == nil {
|
||||||
return nil, notFound
|
return nil, errNotFound
|
||||||
}
|
}
|
||||||
bitpos += node.bits
|
bitpos += node.bits
|
||||||
node = st
|
node = st
|
||||||
|
|
@ -245,7 +245,7 @@ func (s *MemStore) Get(hash Key) (chunk *Chunk, err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = notFound
|
err = errNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ func TestMemStore2_100(t *testing.T) {
|
||||||
func TestMemStoreNotFound(t *testing.T) {
|
func TestMemStoreNotFound(t *testing.T) {
|
||||||
m := NewMemStore(nil, defaultCacheCapacity)
|
m := NewMemStore(nil, defaultCacheCapacity)
|
||||||
_, err := m.Get(ZeroKey)
|
_, err := m.Get(ZeroKey)
|
||||||
if err != notFound {
|
if err != errNotFound {
|
||||||
t.Errorf("Expected notFound, got %v", err)
|
t.Errorf("Expected errNotFound, got %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ var (
|
||||||
// Swarm is the swarm stack.
|
// Swarm is the swarm stack.
|
||||||
type Swarm struct {
|
type Swarm struct {
|
||||||
config *api.Config // swarm configuration
|
config *api.Config // swarm configuration
|
||||||
api *api.Api // high level api layer (fs/manifest)
|
api *api.API // high level api layer (fs/manifest)
|
||||||
dns api.Resolver // DNS registrar
|
dns api.Resolver // DNS registrar
|
||||||
dbAccess *network.DbAccess // access to local chunk db iterator and storage counter
|
dbAccess *network.DbAccess // access to local chunk db iterator and storage counter
|
||||||
storage storage.ChunkStore // internal access to storage, common interface to cloud storage backends
|
storage storage.ChunkStore // internal access to storage, common interface to cloud storage backends
|
||||||
|
|
@ -77,14 +77,14 @@ type Swarm struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type SwarmAPI struct {
|
type SwarmAPI struct {
|
||||||
Api *api.Api
|
API *api.API
|
||||||
Backend chequebook.Backend
|
Backend chequebook.Backend
|
||||||
PrvKey *ecdsa.PrivateKey
|
PrvKey *ecdsa.PrivateKey
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Swarm) API() *SwarmAPI {
|
func (s *Swarm) API() *SwarmAPI {
|
||||||
return &SwarmAPI{
|
return &SwarmAPI{
|
||||||
Api: s.api,
|
API: s.api,
|
||||||
Backend: s.backend,
|
Backend: s.backend,
|
||||||
PrvKey: s.privateKey,
|
PrvKey: s.privateKey,
|
||||||
}
|
}
|
||||||
|
|
@ -162,7 +162,7 @@ func NewSwarm(ctx *node.ServiceContext, backend chequebook.Backend, config *api.
|
||||||
self.dns = api.NewMultiResolver(opts...)
|
self.dns = api.NewMultiResolver(opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.api = api.NewApi(self.dpa, self.dns)
|
self.api = api.NewAPI(self.dpa, self.dns)
|
||||||
// Manifests for Smart Hosting
|
// Manifests for Smart Hosting
|
||||||
log.Debug(fmt.Sprintf("-> Web3 virtual server API"))
|
log.Debug(fmt.Sprintf("-> Web3 virtual server API"))
|
||||||
|
|
||||||
|
|
@ -360,14 +360,14 @@ func (s *Swarm) Stop() error {
|
||||||
|
|
||||||
// Protocols implements the node.Service interface
|
// Protocols implements the node.Service interface
|
||||||
func (s *Swarm) Protocols() []p2p.Protocol {
|
func (s *Swarm) Protocols() []p2p.Protocol {
|
||||||
proto, err := network.Bzz(s.depo, s.backend, s.hive, s.dbAccess, s.config.Swap, s.config.SyncParams, s.config.NetworkId)
|
proto, err := network.Bzz(s.depo, s.backend, s.hive, s.dbAccess, s.config.Swap, s.config.SyncParams, s.config.NetworkID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return []p2p.Protocol{proto}
|
return []p2p.Protocol{proto}
|
||||||
}
|
}
|
||||||
|
|
||||||
// APIs implements node.Service returns the RPC Api descriptors the Swarm implementation offers.
|
// APIs implements node.Service returns the RPC API descriptors the Swarm implementation offers.
|
||||||
func (s *Swarm) APIs() []rpc.API {
|
func (s *Swarm) APIs() []rpc.API {
|
||||||
return []rpc.API{
|
return []rpc.API{
|
||||||
// public APIs
|
// public APIs
|
||||||
|
|
@ -414,7 +414,7 @@ func (s *Swarm) APIs() []rpc.API {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Swarm) Api() *api.Api {
|
func (s *Swarm) Api() *api.API {
|
||||||
return s.api
|
return s.api
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -448,7 +448,7 @@ func NewLocalSwarm(datadir, port string) (self *Swarm, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
self = &Swarm{
|
self = &Swarm{
|
||||||
api: api.NewApi(dpa, nil),
|
api: api.NewAPI(dpa, nil),
|
||||||
config: config,
|
config: config,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ func NewTestSwarmServer(t *testing.T) *TestSwarmServer {
|
||||||
ChunkStore: localStore,
|
ChunkStore: localStore,
|
||||||
}
|
}
|
||||||
dpa.Start()
|
dpa.Start()
|
||||||
a := api.NewApi(dpa, nil)
|
a := api.NewAPI(dpa, nil)
|
||||||
srv := httptest.NewServer(httpapi.NewServer(a))
|
srv := httptest.NewServer(httpapi.NewServer(a))
|
||||||
return &TestSwarmServer{
|
return &TestSwarmServer{
|
||||||
Server: srv,
|
Server: srv,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue