From 2158dbc10a33071dbd5ba1588969cd401e6de761 Mon Sep 17 00:00:00 2001 From: Kiel barry Date: Thu, 7 Jun 2018 17:31:23 -0700 Subject: [PATCH] swarm: wip golint warnings and cmd --- cmd/swarm/config.go | 12 ++++++------ cmd/swarm/config_test.go | 24 ++++++++++++------------ cmd/swarm/main.go | 10 +++++----- swarm/api/api_test.go | 12 ++++++------ swarm/api/filesystem.go | 4 ++-- swarm/api/filesystem_test.go | 2 +- swarm/api/http/server.go | 6 +++--- swarm/api/manifest.go | 10 +++++----- swarm/api/storage.go | 4 ++-- swarm/api/storage_test.go | 2 +- swarm/api/testapi.go | 4 ++-- swarm/fuse/swarmfs.go | 4 ++-- swarm/fuse/swarmfs_test.go | 8 ++++---- swarm/fuse/swarmfs_unix.go | 4 ++-- swarm/network/depo.go | 8 ++++---- swarm/network/forwarding.go | 6 +++--- swarm/network/hive.go | 4 ++-- swarm/network/kademlia/kademlia.go | 4 ++-- swarm/network/protocol.go | 10 +++++----- swarm/network/syncdb.go | 6 +++--- swarm/network/syncer.go | 6 +++--- swarm/storage/common_test.go | 2 +- swarm/storage/dbstore.go | 2 +- swarm/storage/dbstore_test.go | 4 ++-- swarm/storage/memstore.go | 4 ++-- swarm/storage/memstore_test.go | 4 ++-- swarm/swarm.go | 16 ++++++++-------- swarm/testutil/http.go | 2 +- 28 files changed, 92 insertions(+), 92 deletions(-) diff --git a/cmd/swarm/config.go b/cmd/swarm/config.go index adac772bab..a17a07e492 100644 --- a/cmd/swarm/config.go +++ b/cmd/swarm/config.go @@ -168,7 +168,7 @@ func cmdLineOverride(currentConfig *bzzapi.Config, ctx *cli.Context) *bzzapi.Con if networkid := ctx.GlobalString(SwarmNetworkIdFlag.Name); networkid != "" { 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.SwapApi = ctx.GlobalString(SwarmSwapAPIFlag.Name) - if currentConfig.SwapEnabled && currentConfig.SwapApi == "" { + currentConfig.SwapAPI = ctx.GlobalString(SwarmSwapAPIFlag.Name) + if currentConfig.SwapEnabled && currentConfig.SwapAPI == "" { 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 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 != "" { - currentConfig.SwapApi = swapapi + currentConfig.SwapAPI = swapapi } - if currentConfig.SwapEnabled && currentConfig.SwapApi == "" { + if currentConfig.SwapEnabled && currentConfig.SwapAPI == "" { utils.Fatalf(SWARM_ERR_SWAP_SET_NO_API) } diff --git a/cmd/swarm/config_test.go b/cmd/swarm/config_test.go index 9bf584f50c..91e02e1553 100644 --- a/cmd/swarm/config_test.go +++ b/cmd/swarm/config_test.go @@ -120,8 +120,8 @@ func TestCmdLineOverrides(t *testing.T) { t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port) } - if info.NetworkId != 42 { - t.Fatalf("Expected network ID to be %d, got %d", 42, info.NetworkId) + if info.NetworkID != 42 { + t.Fatalf("Expected network ID to be %d, got %d", 42, info.NetworkID) } if !info.SyncEnabled { @@ -148,7 +148,7 @@ func TestFileOverrides(t *testing.T) { defaultConf := api.NewDefaultConfig() //change some values in order to test if they have been loaded defaultConf.SyncEnabled = true - defaultConf.NetworkId = 54 + defaultConf.NetworkID = 54 defaultConf.Port = httpPort defaultConf.StoreParams.DbCapacity = 9000000 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) } - if info.NetworkId != 54 { - t.Fatalf("Expected network ID to be %d, got %d", 54, info.NetworkId) + if info.NetworkID != 54 { + t.Fatalf("Expected network ID to be %d, got %d", 54, info.NetworkID) } if !info.SyncEnabled { @@ -224,7 +224,7 @@ func TestFileOverrides(t *testing.T) { } 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 { @@ -326,8 +326,8 @@ func TestEnvVars(t *testing.T) { t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port) } - if info.NetworkId != 999 { - t.Fatalf("Expected network ID to be %d, got %d", 999, info.NetworkId) + if info.NetworkID != 999 { + t.Fatalf("Expected network ID to be %d, got %d", 999, info.NetworkID) } if info.Cors != "*" { @@ -355,7 +355,7 @@ func TestCmdLineOverridesFile(t *testing.T) { defaultConf := api.NewDefaultConfig() //change some values in order to test if they have been loaded defaultConf.SyncEnabled = false - defaultConf.NetworkId = 54 + defaultConf.NetworkID = 54 defaultConf.Port = "8588" defaultConf.StoreParams.DbCapacity = 9000000 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) } - if info.NetworkId != expectNetworkId { - t.Fatalf("Expected network ID to be %d, got %d", expectNetworkId, info.NetworkId) + if info.NetworkID != expectNetworkId { + t.Fatalf("Expected network ID to be %d, got %d", expectNetworkId, info.NetworkID) } if !info.SyncEnabled { @@ -436,7 +436,7 @@ func TestCmdLineOverridesFile(t *testing.T) { } 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 { diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go index 360020b77b..089c30c79d 100644 --- a/cmd/swarm/main.go +++ b/cmd/swarm/main.go @@ -439,7 +439,7 @@ func bzzd(ctx *cli.Context) error { bootnodes := strings.Split(bzzconfig.BootNodes, ",") injectBootnodes(stack.Server(), bootnodes) } else { - if bzzconfig.NetworkId == 3 { + if bzzconfig.NetworkID == 3 { 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) { var swapClient *ethclient.Client var err error - if bzzconfig.SwapApi != "" { - log.Info("connecting to SWAP API", "url", bzzconfig.SwapApi) - swapClient, err = ethclient.Dial(bzzconfig.SwapApi) + if bzzconfig.SwapAPI != "" { + log.Info("connecting to SWAP API", "url", bzzconfig.SwapAPI) + swapClient, err = ethclient.Dial(bzzconfig.SwapAPI) 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) } } diff --git a/swarm/api/api_test.go b/swarm/api/api_test.go index bdee3f2876..ceaf960a96 100644 --- a/swarm/api/api_test.go +++ b/swarm/api/api_test.go @@ -29,7 +29,7 @@ import ( "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") if err != nil { t.Fatalf("unable to create temp dir: %v", err) @@ -40,7 +40,7 @@ func testAPI(t *testing.T, f func(*Api)) { if err != nil { return } - api := NewApi(dpa, nil) + api := NewAPI(dpa, nil) dpa.Start() f(api) dpa.Stop() @@ -82,8 +82,8 @@ func expResponse(content string, mimeType string, status int) *Response { 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, path string) *testResponse { +// func testGet(t *testing.T, api *API, bzzhash string) *testResponse { +func testGet(t *testing.T, api *API, bzzhash, path string) *testResponse { key := storage.Key(common.Hex2Bytes(bzzhash)) reader, mimeType, status, err := api.Get(key, path) if err != nil { @@ -106,7 +106,7 @@ func testGet(t *testing.T, api *Api, bzzhash, path string) *testResponse { } func TestApiPut(t *testing.T) { - testAPI(t, func(api *Api) { + testAPI(t, func(api *API) { content := "hello" exp := expResponse(content, "text/plain", 0) // exp := expResponse([]byte(content), "text/plain", 0) @@ -213,7 +213,7 @@ func TestAPIResolve(t *testing.T) { } for _, x := range tests { 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"} if x.immutable { uri.Scheme = "bzz-immutable" diff --git a/swarm/api/filesystem.go b/swarm/api/filesystem.go index d9434072fb..de67dc75fd 100644 --- a/swarm/api/filesystem.go +++ b/swarm/api/filesystem.go @@ -34,10 +34,10 @@ import ( const maxParallelFiles = 5 type FileSystem struct { - api *Api + api *API } -func NewFileSystem(api *Api) *FileSystem { +func NewFileSystem(api *API) *FileSystem { return &FileSystem{api} } diff --git a/swarm/api/filesystem_test.go b/swarm/api/filesystem_test.go index 8a15e735dc..4f8c0209b3 100644 --- a/swarm/api/filesystem_test.go +++ b/swarm/api/filesystem_test.go @@ -31,7 +31,7 @@ import ( var testDownloadDir, _ = ioutil.TempDir(os.TempDir(), "bzz-test") func testFileSystem(t *testing.T, f func(*FileSystem)) { - testApi(t, func(api *Api) { + testAPI(t, func(api *API) { f(NewFileSystem(api)) }) } diff --git a/swarm/api/http/server.go b/swarm/api/http/server.go index c03b4e33e4..7a1ce12e4a 100644 --- a/swarm/api/http/server.go +++ b/swarm/api/http/server.go @@ -79,7 +79,7 @@ type ServerConfig struct { // https://github.com/atom/electron/blob/master/docs/api/protocol.md // StartHTTPServer starts up http server -func StartHTTPServer(api *api.Api, config *ServerConfig) { +func StartHTTPServer(api *api.API, config *ServerConfig) { var allowedOrigins []string for _, domain := range strings.Split(config.CorsString, ",") { allowedOrigins = append(allowedOrigins, strings.TrimSpace(domain)) @@ -95,12 +95,12 @@ func StartHTTPServer(api *api.Api, config *ServerConfig) { go http.ListenAndServe(config.Addr, hdlr) } -func NewServer(api *api.Api) *Server { +func NewServer(api *api.API) *Server { return &Server{api} } type Server struct { - api *api.Api + api *api.API } // Request wraps http.Request and also includes the parsed bzz URI diff --git a/swarm/api/manifest.go b/swarm/api/manifest.go index 96c40ae6fb..8a94547a2b 100644 --- a/swarm/api/manifest.go +++ b/swarm/api/manifest.go @@ -59,7 +59,7 @@ type ManifestList struct { } // 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 data, err := json.Marshal(&manifest) 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 type ManifestWriter struct { - api *Api + api *API trie *manifestTrie 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) if err != nil { 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 // all of its submanifests type ManifestWalker struct { - api *Api + api *API trie *manifestTrie 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) if err != nil { return nil, fmt.Errorf("error loading manifest %s: %s", key, err) diff --git a/swarm/api/storage.go b/swarm/api/storage.go index 60006626e5..6fb5df8444 100644 --- a/swarm/api/storage.go +++ b/swarm/api/storage.go @@ -30,10 +30,10 @@ type Response struct { // // DEPRECATED: Use the HTTP API instead type Storage struct { - api *Api + api *API } -func NewStorage(api *Api) *Storage { +func NewStorage(api *API) *Storage { return &Storage{api} } diff --git a/swarm/api/storage_test.go b/swarm/api/storage_test.go index d260dd61d8..49d8f921c4 100644 --- a/swarm/api/storage_test.go +++ b/swarm/api/storage_test.go @@ -21,7 +21,7 @@ import ( ) func testStorage(t *testing.T, f func(*Storage)) { - testApi(t, func(api *Api) { + testAPI(t, func(api *API) { f(NewStorage(api)) }) } diff --git a/swarm/api/testapi.go b/swarm/api/testapi.go index 35031f3bf8..209e30b57b 100644 --- a/swarm/api/testapi.go +++ b/swarm/api/testapi.go @@ -21,11 +21,11 @@ import ( ) type Control struct { - api *Api + api *API hive *network.Hive } -func NewControl(api *Api, hive *network.Hive) *Control { +func NewControl(api *API, hive *network.Hive) *Control { return &Control{api, hive} } diff --git a/swarm/fuse/swarmfs.go b/swarm/fuse/swarmfs.go index 44b6331281..b2489b721c 100644 --- a/swarm/fuse/swarmfs.go +++ b/swarm/fuse/swarmfs.go @@ -39,12 +39,12 @@ var ( ) type SwarmFS struct { - swarmAPI *api.Api + swarmAPI *api.API activeMounts map[string]*MountInfo swarmFsLock *sync.RWMutex } -func NewSwarmFS(api *api.Api) *SwarmFS { +func NewSwarmFS(api *api.API) *SwarmFS { swarmfsLock.Do(func() { swarmfs = &SwarmFS{ swarmAPI: api, diff --git a/swarm/fuse/swarmfs_test.go b/swarm/fuse/swarmfs_test.go index 42af36345f..bbd7c9f6bc 100644 --- a/swarm/fuse/swarmfs_test.go +++ b/swarm/fuse/swarmfs_test.go @@ -38,7 +38,7 @@ type fileInfo struct { 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) for fname, finfo := range files { @@ -70,7 +70,7 @@ func createTestFilesAndUploadToSwarm(t *testing.T, api *api.Api, files map[strin 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.MkdirAll(mountDir, 0777) swarmfs := NewSwarmFS(api) @@ -190,7 +190,7 @@ func isDirEmpty(name string) bool { } type testAPI struct { - api *api.Api + api *api.API } func (ta *testAPI) mountListAndUnmount(t *testing.T) { @@ -812,7 +812,7 @@ func TestFUSE(t *testing.T) { if err != nil { t.Fatal(err) } - ta := &testAPI{api: api.NewApi(dpa, nil)} + ta := &testAPI{api: api.NewAPI(dpa, nil)} dpa.Start() defer dpa.Stop() diff --git a/swarm/fuse/swarmfs_unix.go b/swarm/fuse/swarmfs_unix.go index d0c23cbb44..08d0e0393b 100644 --- a/swarm/fuse/swarmfs_unix.go +++ b/swarm/fuse/swarmfs_unix.go @@ -55,11 +55,11 @@ type MountInfo struct { LatestManifest string rootDir *SwarmDir fuseConnection *fuse.Conn - swarmAPI *api.Api + swarmAPI *api.API lock *sync.RWMutex } -func NewMountInfo(mhash, mpoint string, sapi *api.Api) *MountInfo { +func NewMountInfo(mhash, mpoint string, sapi *api.API) *MountInfo { newMountInfo := &MountInfo{ MountPoint: mpoint, StartManifest: mhash, diff --git a/swarm/network/depo.go b/swarm/network/depo.go index 666ae7b19f..519015fcd0 100644 --- a/swarm/network/depo.go +++ b/swarm/network/depo.go @@ -177,7 +177,7 @@ func (d *Depo) HandleRetrieveRequestMsg(req *retrieveRequestMsgData, p *peer) { if req.MaxSize == 0 || int64(req.MaxSize) >= chunk.Size { sreq := &storeRequestMsgData{ - Id: req.Id, + ID: req.ID, Key: chunk.Key, SData: chunk.SData, 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) */ 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)) - list := rs.Requesters[req.Id] - rs.Requesters[req.Id] = append(list, req) + log.Trace(fmt.Sprintf("Depo.addRequester: key %v - add peer to req.ID %v", req.Key.Log(), req.ID)) + list := rs.Requesters[req.ID] + rs.Requesters[req.ID] = append(list, req) } diff --git a/swarm/network/forwarding.go b/swarm/network/forwarding.go index 7b9d906dd7..2cb59efdd1 100644 --- a/swarm/network/forwarding.go +++ b/swarm/network/forwarding.go @@ -70,7 +70,7 @@ OUT: } req := &retrieveRequestMsgData{ Key: chunk.Key, - Id: generateID(), + ID: generateID(), } var err error if p.swap != nil { @@ -123,8 +123,8 @@ func (f *forwarder) Deliver(chunk *storage.Chunk) { for id, r := range requesters { req = r.(*retrieveRequestMsgData) if req.timeout == nil || req.timeout.After(time.Now()) { - log.Trace(fmt.Sprintf("forwarder.Deliver: %v -> %v", req.Id, req.from)) - msg.Id = uint64(id) + log.Trace(fmt.Sprintf("forwarder.Deliver: %v -> %v", req.ID, req.from)) + msg.ID = uint64(id) Deliver(req.from, msg, DeliverReq) n++ counter-- diff --git a/swarm/network/hive.go b/swarm/network/hive.go index 560d5f9305..e6a71c90ed 100644 --- a/swarm/network/hive.go +++ b/swarm/network/hive.go @@ -386,12 +386,12 @@ func (h *Hive) peers(req *retrieveRequestMsgData) { for _, peer := range h.getPeers(key, int(req.MaxPeers)) { 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{ Peers: addrs, Key: req.Key, - Id: req.Id, + ID: req.ID, } peersData.setTimeout(req.timeout) req.from.peers(peersData) diff --git a/swarm/network/kademlia/kademlia.go b/swarm/network/kademlia/kademlia.go index 1ac638f80c..df022b8577 100644 --- a/swarm/network/kademlia/kademlia.go +++ b/swarm/network/kademlia/kademlia.go @@ -88,7 +88,7 @@ type Kademlia struct { type Node interface { Addr() Address - Url() string + URL() string LastActive() time.Time Drop() } @@ -132,7 +132,7 @@ func (k *Kademlia) On(node Node, cb func(*NodeRecord, Node) error) (err error) { k.lock.Lock() 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 { err = cb(record, node) diff --git a/swarm/network/protocol.go b/swarm/network/protocol.go index ea53be8fe0..51a4b4a0bb 100644 --- a/swarm/network/protocol.go +++ b/swarm/network/protocol.go @@ -330,7 +330,7 @@ func (b *bzz) handleStatus() (err error) { handshake := &statusMsgData{ Version: uint64(Version), ID: "honey", - Addr: b.bAddr(), + Addr: b.selfAddr(), NetworkID: b.NetworkID, Swap: &bzzswap.SwapProfile{ Profile: b.swapParams.Profile, @@ -374,7 +374,7 @@ func (b *bzz) handleStatus() (err error) { } 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 { // set remote profile for accounting @@ -410,7 +410,7 @@ func (b *bzz) sync(state *syncState) error { // an explicitly received nil syncstate disables syncronisation if state == nil { 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} } else { state.synced = make(chan bool) @@ -419,7 +419,7 @@ func (b *bzz) sync(state *syncState) error { state.Start = storage.Key(start[:]) 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 b.syncer, err = newSyncer( @@ -432,7 +432,7 @@ func (b *bzz) sync(state *syncState) error { if err != 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 } diff --git a/swarm/network/syncdb.go b/swarm/network/syncdb.go index cc5f5cac27..c9aa7e44dc 100644 --- a/swarm/network/syncdb.go +++ b/swarm/network/syncdb.go @@ -358,13 +358,13 @@ func (d *syncDb) newSyncDbEntry(req interface{}, counter uint64) (entry *syncDbE var sreq *storeRequestMsgData if key, ok = req.(storage.Key); ok { - id = generateId() + id = generateID() } else if chunk, ok = req.(*storage.Chunk); ok { key = chunk.Key - id = generateId() + id = generateID() } else if sreq, ok = req.(*storeRequestMsgData); ok { key = sreq.Key - id = sreq.Id + id = sreq.ID } else if entry, ok = req.(*syncDbEntry); !ok { return nil, fmt.Errorf("type not allowed: %v (%T)", req, req) } diff --git a/swarm/network/syncer.go b/swarm/network/syncer.go index c0a327da0a..9a9813dd1a 100644 --- a/swarm/network/syncer.go +++ b/swarm/network/syncer.go @@ -738,7 +738,7 @@ func (s *syncer) newStoreRequestMsgData(req interface{}) (*storeRequestMsgData, } sreq = &storeRequestMsgData{ - Id: id, + ID: id, Key: chunk.Key, SData: chunk.SData, } @@ -759,7 +759,7 @@ func parseRequest(req interface{}) (storage.Key, uint64, *storage.Chunk, *storeR var err error if key, ok = req.(storage.Key); ok { - id = generateId() + id = generateID() } else if entry, ok = req.(*syncDbEntry); ok { 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 { key = chunk.Key - id = generateId() + id = generateID() } else if sreq, ok = req.(*storeRequestMsgData); ok { key = sreq.Key diff --git a/swarm/storage/common_test.go b/swarm/storage/common_test.go index b904f02904..d8493294b3 100644 --- a/swarm/storage/common_test.go +++ b/swarm/storage/common_test.go @@ -90,7 +90,7 @@ func testStore(m ChunkStore, l int64, branches int64, t *testing.T) { for ch := range chunkC { go func(chunk *Chunk) { storedChunk, err := m.Get(chunk.Key) - if err == notFound { + if err == errNotFound { log.Trace(fmt.Sprintf("chunk '%v' not found", chunk.Key.Log())) } else if err != nil { log.Trace(fmt.Sprintf("error retrieving chunk %v: %v", chunk.Key.Log(), err)) diff --git a/swarm/storage/dbstore.go b/swarm/storage/dbstore.go index 117c96fee0..d99d37bb4a 100644 --- a/swarm/storage/dbstore.go +++ b/swarm/storage/dbstore.go @@ -495,7 +495,7 @@ func (s *DbStore) Get(key Key) (chunk *Chunk, err error) { } decodeData(data, chunk) } else { - err = notFound + err = errNotFound } return diff --git a/swarm/storage/dbstore_test.go b/swarm/storage/dbstore_test.go index dd165b5768..59aa2c23d6 100644 --- a/swarm/storage/dbstore_test.go +++ b/swarm/storage/dbstore_test.go @@ -66,8 +66,8 @@ func TestDbStoreNotFound(t *testing.T) { m := initDbStore(t) defer m.Close() _, err := m.Get(ZeroKey) - if err != notFound { - t.Errorf("Expected notFound, got %v", err) + if err != errNotFound { + t.Errorf("Expected errNotFound, got %v", err) } } diff --git a/swarm/storage/memstore.go b/swarm/storage/memstore.go index 675563044c..39c3cc337a 100644 --- a/swarm/storage/memstore.go +++ b/swarm/storage/memstore.go @@ -227,7 +227,7 @@ func (s *MemStore) Get(hash Key) (chunk *Chunk, err error) { l := hash.bits(bitpos, node.bits) st := node.subtree[l] if st == nil { - return nil, notFound + return nil, errNotFound } bitpos += node.bits node = st @@ -245,7 +245,7 @@ func (s *MemStore) Get(hash Key) (chunk *Chunk, err error) { } } } else { - err = notFound + err = errNotFound } return diff --git a/swarm/storage/memstore_test.go b/swarm/storage/memstore_test.go index 2e0ab535af..ea27e68683 100644 --- a/swarm/storage/memstore_test.go +++ b/swarm/storage/memstore_test.go @@ -44,7 +44,7 @@ func TestMemStore2_100(t *testing.T) { func TestMemStoreNotFound(t *testing.T) { m := NewMemStore(nil, defaultCacheCapacity) _, err := m.Get(ZeroKey) - if err != notFound { - t.Errorf("Expected notFound, got %v", err) + if err != errNotFound { + t.Errorf("Expected errNotFound, got %v", err) } } diff --git a/swarm/swarm.go b/swarm/swarm.go index 1ac75fee87..adb73469e5 100644 --- a/swarm/swarm.go +++ b/swarm/swarm.go @@ -60,7 +60,7 @@ var ( // Swarm is the swarm stack. type Swarm struct { 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 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 @@ -77,14 +77,14 @@ type Swarm struct { } type SwarmAPI struct { - Api *api.Api + API *api.API Backend chequebook.Backend PrvKey *ecdsa.PrivateKey } func (s *Swarm) API() *SwarmAPI { return &SwarmAPI{ - Api: s.api, + API: s.api, Backend: s.backend, PrvKey: s.privateKey, } @@ -162,7 +162,7 @@ func NewSwarm(ctx *node.ServiceContext, backend chequebook.Backend, config *api. 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 log.Debug(fmt.Sprintf("-> Web3 virtual server API")) @@ -360,14 +360,14 @@ func (s *Swarm) Stop() error { // Protocols implements the node.Service interface 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 { return nil } 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 { return []rpc.API{ // 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 } @@ -448,7 +448,7 @@ func NewLocalSwarm(datadir, port string) (self *Swarm, err error) { } self = &Swarm{ - api: api.NewApi(dpa, nil), + api: api.NewAPI(dpa, nil), config: config, } diff --git a/swarm/testutil/http.go b/swarm/testutil/http.go index f2922fab00..4750e6b9a5 100644 --- a/swarm/testutil/http.go +++ b/swarm/testutil/http.go @@ -49,7 +49,7 @@ func NewTestSwarmServer(t *testing.T) *TestSwarmServer { ChunkStore: localStore, } dpa.Start() - a := api.NewApi(dpa, nil) + a := api.NewAPI(dpa, nil) srv := httptest.NewServer(httpapi.NewServer(a)) return &TestSwarmServer{ Server: srv,