aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/api
diff options
context:
space:
mode:
Diffstat (limited to 'swarm/api')
-rw-r--r--swarm/api/config.go19
-rw-r--r--swarm/api/config_test.go1
-rw-r--r--swarm/api/http/server.go1
-rw-r--r--swarm/api/manifest.go4
-rw-r--r--swarm/api/manifest_test.go33
5 files changed, 47 insertions, 11 deletions
diff --git a/swarm/api/config.go b/swarm/api/config.go
index 23a855500..647c153ed 100644
--- a/swarm/api/config.go
+++ b/swarm/api/config.go
@@ -32,7 +32,8 @@ import (
)
const (
- port = "8500"
+ DefaultHTTPListenAddr = "127.0.0.1"
+ DefaultHTTPPort = "8500"
)
var (
@@ -48,12 +49,13 @@ type Config struct {
*network.HiveParams
Swap *swap.SwapParams
*network.SyncParams
- Path string
- Port string
- PublicKey string
- BzzKey string
- EnsRoot common.Address
- NetworkId uint64
+ Path string
+ ListenAddr string
+ Port string
+ PublicKey string
+ BzzKey string
+ EnsRoot common.Address
+ NetworkId uint64
}
// config is agnostic to where private key is coming from
@@ -76,7 +78,8 @@ func NewConfig(path string, contract common.Address, prvKey *ecdsa.PrivateKey, n
HiveParams: network.NewHiveParams(dirpath),
ChunkerParams: storage.NewChunkerParams(),
StoreParams: storage.NewStoreParams(dirpath),
- Port: port,
+ ListenAddr: DefaultHTTPListenAddr,
+ Port: DefaultHTTPPort,
Path: dirpath,
Swap: swap.DefaultSwapParams(contract, prvKey),
PublicKey: pubkeyhex,
diff --git a/swarm/api/config_test.go b/swarm/api/config_test.go
index 2f40098a3..6b5cea915 100644
--- a/swarm/api/config_test.go
+++ b/swarm/api/config_test.go
@@ -80,6 +80,7 @@ var (
false
],
"Path": "TMPDIR",
+ "ListenAddr": "127.0.0.1",
"Port": "8500",
"PublicKey": "0x045f5cfd26692e48d0017d380349bcf50982488bc11b5145f3ddf88b24924299048450542d43527fbe29a5cb32f38d62755393ac002e6bfdd71b8d7ba725ecd7a3",
"BzzKey": "0xe861964402c0b78e2d44098329b8545726f215afa737d803714a4338552fcb81",
diff --git a/swarm/api/http/server.go b/swarm/api/http/server.go
index 849b9e10f..5f64f971b 100644
--- a/swarm/api/http/server.go
+++ b/swarm/api/http/server.go
@@ -69,7 +69,6 @@ func StartHttpServer(api *api.Api, config *ServerConfig) {
hdlr := c.Handler(NewServer(api))
go http.ListenAndServe(config.Addr, hdlr)
- log.Info(fmt.Sprintf("Swarm HTTP proxy started on localhost:%s", config.Addr))
}
func NewServer(api *api.Api) *Server {
diff --git a/swarm/api/manifest.go b/swarm/api/manifest.go
index dbaaf4bff..e251620a7 100644
--- a/swarm/api/manifest.go
+++ b/swarm/api/manifest.go
@@ -237,12 +237,12 @@ func (self *manifestTrie) addEntry(entry *manifestTrieEntry, quitC chan bool) {
}
b := byte(entry.Path[0])
- if (self.entries[b] == nil) || (self.entries[b].Path == entry.Path) {
+ oldentry := self.entries[b]
+ if (oldentry == nil) || (oldentry.Path == entry.Path && oldentry.ContentType != ManifestType) {
self.entries[b] = entry
return
}
- oldentry := self.entries[b]
cpl := 0
for (len(entry.Path) > cpl) && (len(oldentry.Path) > cpl) && (entry.Path[cpl] == oldentry.Path[cpl]) {
cpl++
diff --git a/swarm/api/manifest_test.go b/swarm/api/manifest_test.go
index 20b8117c6..0208848a3 100644
--- a/swarm/api/manifest_test.go
+++ b/swarm/api/manifest_test.go
@@ -18,6 +18,8 @@ package api
import (
// "encoding/json"
+ "bytes"
+ "encoding/json"
"fmt"
"io"
"strings"
@@ -78,3 +80,34 @@ func TestGetEntry(t *testing.T) {
func TestDeleteEntry(t *testing.T) {
}
+
+// TestAddFileWithManifestPath tests that adding an entry at a path which
+// already exists as a manifest just adds the entry to the manifest rather
+// than replacing the manifest with the entry
+func TestAddFileWithManifestPath(t *testing.T) {
+ // create a manifest containing "ab" and "ac"
+ manifest, _ := json.Marshal(&Manifest{
+ Entries: []ManifestEntry{
+ {Path: "ab", Hash: "ab"},
+ {Path: "ac", Hash: "ac"},
+ },
+ })
+ reader := &storage.LazyTestSectionReader{
+ SectionReader: io.NewSectionReader(bytes.NewReader(manifest), 0, int64(len(manifest))),
+ }
+ trie, err := readManifest(reader, nil, nil, nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ checkEntry(t, "ab", "ab", trie)
+ checkEntry(t, "ac", "ac", trie)
+
+ // now add path "a" and check we can still get "ab" and "ac"
+ entry := &manifestTrieEntry{}
+ entry.Path = "a"
+ entry.Hash = "a"
+ trie.addEntry(entry, nil)
+ checkEntry(t, "ab", "ab", trie)
+ checkEntry(t, "ac", "ac", trie)
+ checkEntry(t, "a", "a", trie)
+}