This repository has been archived by the owner on Aug 2, 2021. It is now read-only.
client: add bzz client, update smoke tests #1582
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package client | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/ethereum/go-ethereum/rpc" | ||
"github.com/ethersphere/swarm/log" | ||
"github.com/ethersphere/swarm/storage" | ||
) | ||
|
||
type Bzz struct { | ||
client *rpc.Client | ||
} | ||
|
||
// NewBzz is a constructor for a Bzz API | ||
func NewBzz(client *rpc.Client) *Bzz { | ||
return &Bzz{ | ||
client: client, | ||
} | ||
} | ||
|
||
// GetChunksBitVector returns a bit vector of presence for a given slice of chunks | ||
func (b *Bzz) GetChunksBitVector(addrs []storage.Address) (string, error) { | ||
var hostChunks string | ||
const trackChunksPageSize = 7500 | ||
|
||
for len(addrs) > 0 { | ||
var pageChunks string | ||
// get current page size, so that we avoid a slice out of bounds on the last page | ||
pagesize := trackChunksPageSize | ||
if len(addrs) < trackChunksPageSize { | ||
pagesize = len(addrs) | ||
} | ||
|
||
err := b.client.Call(&pageChunks, "bzz_has", addrs[:pagesize]) | ||
if err != nil { | ||
return "", err | ||
} | ||
hostChunks += pageChunks | ||
addrs = addrs[pagesize:] | ||
} | ||
|
||
return hostChunks, nil | ||
} | ||
|
||
// GetBzzAddr returns the bzzAddr of the node | ||
func (b *Bzz) GetBzzAddr() (string, error) { | ||
var hive string | ||
|
||
err := b.client.Call(&hive, "bzz_hive") | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
// we make an ugly assumption about the output format of the hive.String() method | ||
// ideally we should replace this with an API call that returns the bzz addr for a given host, | ||
// but this also works for now (provided we don't change the hive.String() method, which we haven't in some time | ||
ss := strings.Split(strings.Split(hive, "\n")[3], " ") | ||
return ss[len(ss)-1], nil | ||
} | ||
|
||
// IsPullSyncing is checking if the node is still receiving chunk deliveries due to pull syncing | ||
func (b *Bzz) IsPullSyncing() (bool, error) { | ||
var isSyncing bool | ||
|
||
err := b.client.Call(&isSyncing, "bzz_isPullSyncing") | ||
if err != nil { | ||
log.Error("error calling host for isPullSyncing", "err", err) | ||
return false, err | ||
} | ||
|
||
return isSyncing, nil | ||
} | ||
|
||
// IsPushSynced checks if the given `tag` is done syncing, i.e. we've received receipts for all chunks | ||
func (b *Bzz) IsPushSynced(tagname string) (bool, error) { | ||
var isSynced bool | ||
|
||
err := b.client.Call(&isSynced, "bzz_isPushSynced", tagname) | ||
if err != nil { | ||
log.Error("error calling host for isPushSynced", "err", err) | ||
return false, err | ||
} | ||
|
||
return isSynced, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also get the BzzAddr via the
bzz_info
rpc call. From there you want the theBzzKey
field.e.g.