Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Commit

Permalink
chunk, cmd/swarm: return last tag
Browse files Browse the repository at this point in the history
  • Loading branch information
acud committed Oct 2, 2019
1 parent 747ab85 commit bed4ca5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions chunk/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"errors"
"math/rand"
"sync"
"time"

"github.com/ethersphere/swarm/sctx"
)
Expand Down Expand Up @@ -71,14 +72,15 @@ func (ts *Tags) Get(uid uint32) (*Tag, error) {
return t.(*Tag), nil
}

// GetByAddress returns the underlying tag for the address or an error if not found
// GetByAddress returns the latest underlying tag for the address or an error if not found
func (ts *Tags) GetByAddress(address Address) (*Tag, error) {
var t *Tag
var lastTime time.Time
ts.tags.Range(func(key interface{}, value interface{}) bool {
rcvdTag := value.(*Tag)
if bytes.Equal(rcvdTag.Address, address) {
if bytes.Equal(rcvdTag.Address, address) && rcvdTag.StartedAt > lastTime {
t = rcvdTag
return false
lastTime = rcvdTag.StartedAt
}
return true
})
Expand Down
4 changes: 3 additions & 1 deletion cmd/swarm/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ func upload(ctx *cli.Context) {
return client.Upload(f, "", toEncrypt, toPin)
}
}
start := time.Now()

hash, err := doUpload()
if err != nil {
utils.Fatalf("Upload failed: %s", err)
Expand Down Expand Up @@ -202,7 +204,7 @@ func upload(ctx *cli.Context) {
pollTag(client, tag, bars)
}

fmt.Println("Done! took", time.Since(tag.StartedAt))
fmt.Println("Done! took", time.Since(start))
fmt.Println("Your Swarm hash should now be retrievable from other nodes!")
}

Expand Down

0 comments on commit bed4ca5

Please sign in to comment.