Documentation ¶
Overview ¶
common includes definition and interfaces common to several Archon Go packages
Index ¶
- Constants
- Variables
- func Abort(err error)
- func AbortWithString(msg string)
- func ArchonHashFromString(hs string) ([]byte, error)
- func ArchonHashString(hash []byte) string
- func BasicAuthHandler(h http.HandlerFunc) http.HandlerFunc
- func BigEndianUint32(val uint32) []byte
- func BigEndianUint64(val int64) []byte
- func BoolFromQuery(name string, r *http.Request) bool
- func BytesToString(data []byte) string
- func CRC32(input []byte) []byte
- func ChainHandlers(h http.HandlerFunc, middleware ...func(http.HandlerFunc) http.HandlerFunc) http.HandlerFunc
- func CloneStringSlice(a []string) []string
- func CompressString(s string) []byte
- func Contains(target string, list []string) bool
- func CreateFile(fullPath string) (*os.File, error)
- func DefaultToExecutable(path string) string
- func DirSize(path string) (int64, error)
- func DivideRoundUp(numerator, divisor uint64) uint64
- func DownloadFile(w io.Writer, url string) error
- func EraseInt(a []int, x int) []int
- func EraseString(a []string, x string) []string
- func ExtendedSliceToMultipleOf(multiple int, input []byte) []byte
- func FileExists(path string) bool
- func FileSize(path string) int64
- func FileSizeString(fullPath string) string
- func FillRandom(p []byte)
- func FirstLiveUrl(urls []string, port int) string
- func GetAllSeedUrls() []string
- func GetAppConfiguration(config interface{}) error
- func GetArchonHash(data []byte) []byte
- func GetArchonHashOf(r io.Reader) ([]byte, int64, error)
- func GetArchonHashOfFile(filePath string) ([]byte, int64, error)
- func GetConfiguration(config interface{}, path string) error
- func GetFromSP(spUrl, endPoint, query string, timeout time.Duration) (contents string, err error)
- func GetMultiAddressOf(ipOrDns string) (ma.Multiaddr, error)
- func GetPassword(prompt string, show bool) (password string)
- func GetResponse(resp *http.Response) (string, error)
- func GetSeedUrls(wanted int) []string
- func GetTempFile() (f *os.File, err error)
- func I64ToA(i int64) string
- func IndexFromShardPath(shp string) (index int, err error)
- func InitLogging(filePath string)
- func InvalidArgs(msg string)
- func IsFullPath(path string) bool
- func IsLegalFilePath(path string) error
- func IsLegalUserName(userName string) error
- func Join(dir, subpath string) string
- func MakeFolders(folders []string) (err error)
- func MakeStringOfLen(length int) string
- func Max(x, y int) int
- func MegaBytes(numBytes int64) int64
- func Min(x, y int) int
- func NeedArgs(arg string)
- func NewArchonHash() hash.Hash
- func NumBytesDisplayString(s uint64) string
- func NumLines(r io.Reader) (int, error)
- func PickUrl(urls []string, preferHttp bool) string
- func PostFromReader(targetUrl string, r io.Reader, contentType string) (err error)
- func PostFromReaderWithProgress(targetUrl string, r io.Reader, contentType string, progress *ByteProgress) (err error)
- func PromptForInput(prompt string) string
- func RandomInt(lower, upperExclusive int) int
- func RandomInt64(lower, upperExclusive int64) int64
- func RandomIntFromSlice(a []int) int
- func RandomIntRange(n int) []int
- func RandomRange(n, lower, upperExclusive int) []int
- func RandomStringFromSlice(a *[]string) string
- func RawBytesToString(data []byte) string
- func ReadBigEndianInt32(r io.Reader) (v int32, err error)
- func ReadBigEndianInt64(r io.Reader) (v int64, err error)
- func ReadBigEndianUint32(r io.Reader) (v uint32, err error)
- func ReadBigEndianUint64(r io.Reader) (v uint64, err error)
- func ReadByte(r io.Reader) (v byte, err error)
- func ReadExactly(n int, r io.Reader) (data []byte, err error)
- func Rewind(r io.ReadSeeker)
- func RoundUp(numToRound, multiple uint64) uint64
- func SaveAppConfiguration(config interface{}) error
- func SaveConfiguration(conf interface{}, path string) error
- func SeedsPort() int
- func SeparatedStringList(separator string, items ...interface{}) string
- func SetLoggingLevel(level LoggingLevel)
- func SetLoggingLevelFromName(level string)
- func StringKeysOf(m map[string]bool) []string
- func StringToBytes(s string) []byte
- func StringToEthAddress(s string) (ea [20]byte)
- func ToJsonString(data interface{}) string
- func UnCompressString(b []byte) string
- func WaitForCompletion(repeat, timeout time.Duration, task func() (interface{}, bool)) (interface{}, bool)
- func WriteLastLines(w io.Writer, filepath string, numLines int)
- func WriteTempFile(r io.Reader) string
- func Yes(prompt string) bool
- type ArchonHashBytes
- type ArchonSignature
- type ArchonUrl
- type ByteProgress
- type ContainsEpResponse
- type EthAddress
- type HashingWriter
- type LoggingLevel
- type ProgressWriter
- type RetrieveResponse
- type SpProfile
- type SpProfilesResponse
- type StorageProviders
- func (sps *StorageProviders) Add(sp *SpProfile)
- func (sps *StorageProviders) Addresses() (addr []string)
- func (sps *StorageProviders) EthAddresses() [][ecommon.AddressLength]byte
- func (sps *StorageProviders) ForAllProfiles(do func(*SpProfile))
- func (sps *StorageProviders) Get(i int) *SpProfile
- func (sps *StorageProviders) GetOfAddress(addr string) *SpProfile
- func (sps *StorageProviders) Hosts() (hosts []string)
- func (sps *StorageProviders) KeepOnly(n int)
- func (sps *StorageProviders) Num() int
- func (sps *StorageProviders) PickRandom(needed int) StorageProviders
- func (sps *StorageProviders) PriceOfUpload(numBytes int64) (totalPrice int64)
- func (sps *StorageProviders) Remove(removeThis func(profile *SpProfile) bool)
- func (sps *StorageProviders) Set(i int, sp *SpProfile)
- func (sps *StorageProviders) SortByMinAsk(granularity uint64)
- type TransactionHash
- type UrlPermission
- type Urls
Constants ¶
const ( Release = iota Beta Debug )
const ( Kilo = 1000 Mega = Kilo * 1000 Giga = Mega * 1000 Quintillion = Giga * Giga // 10^18 )
const ( ArcProtocol = "arc" ShardFileSuffix = "afs" HashFileSuffix = "afh" WholeFileSuffix = "af" ContainsEndpoint = "/contains" RetrieveEndpoint = "/retrieve" SpProfilesEndpoint = "/spprofiles" StatsEndpoint = "/stats" UploadEndpoint = "/upload" DownloadEndpoint = "/download" )
const ( //--------- for upload -------------- UploadFileKey = "uploadFile" // the key in form-data for the file path TransactionHashQuery = "txHash" OverwriteQuery = "overwrite" HashUrlQuery = "hashUrl" // request for hash URL (rather than named) ChainQuery = "chain" // Ethereum or Neo CloudDir = "cloudDir" //--------- for download ---------------- ShardIdxQuery = "shardIdx" ArchonUrlQuery = "archonUrl" )
Keys and queries
const ArchonHash = crypto.SHA3_256
const ArchonHashLen = 32 // Bytes
const ArchonSignatureLen = ecrypto.SignatureLength //65
const BootStrapNodeId = "QmNX6ASyukLch38D2Z1h4cMh39ATfqqDom1xJWv2YHc1eG"
const BuildConfig = Beta
const Localhost = "192.168.1.161" // Debugging only
const UrlsSep = "|"
const Version = "1.0"
Variables ¶
var ( // Defaults LogTrace *log.Logger = log.New(os.Stderr, "Trace ", log.LstdFlags) LogDebug *log.Logger = log.New(os.Stderr, "Debug ", log.LstdFlags) LogInfo *log.Logger = log.New(os.Stderr, "Info ", log.LstdFlags) LogWarning *log.Logger = log.New(os.Stderr, "Warning ", log.LstdFlags) LogError *log.Logger = log.New(os.Stderr, "Error ", log.LstdFlags) )
Functions ¶
func Abort ¶
func Abort(err error)
Abort does nothing if err is nil, otherwise logs the error and exits
func AbortWithString ¶
func AbortWithString(msg string)
func ArchonHashFromString ¶
func ArchonHashString ¶
ArchonHashString is base58 encoded
func BasicAuthHandler ¶
func BasicAuthHandler(h http.HandlerFunc) http.HandlerFunc
Leverages nemo's answer in http://stackoverflow.com/a/21937924/556573
func BigEndianUint32 ¶
func BigEndianUint64 ¶
func BoolFromQuery ¶
BoolFromQuery return false if query is missing or set to false
func BytesToString ¶
func ChainHandlers ¶
func ChainHandlers(h http.HandlerFunc, middleware ...func(http.HandlerFunc) http.HandlerFunc) http.HandlerFunc
ChainHandlers provides a cleaner interface for chaining middleware for single routes. Middleware functions are simple HTTP handlers (w http.ResponseWriter, r *http.Request)
r.HandleFunc("/login", use(loginHandler, rateLimit, csrf))
See https://gist.github.com/elithrar/7600878#comment-955958 for how to extend it to suit simple http.Handler's
func CloneStringSlice ¶
func CompressString ¶
func DefaultToExecutable ¶
Default to executable returns full path. If input path is relative, it will considered relative to the the folder of the executable
func DivideRoundUp ¶
func DownloadFile ¶
DownloadFile will download a file from a url. Assumes that url is a file download url
func EraseString ¶
func FileExists ¶
func FileSizeString ¶
func FirstLiveUrl ¶
If port is non-zero it will be used for all the urls
func GetAllSeedUrls ¶
func GetAllSeedUrls() []string
func GetAppConfiguration ¶
func GetAppConfiguration(config interface{}) error
func GetArchonHash ¶
func GetConfiguration ¶
func GetPassword ¶
func GetResponse ¶
GetResponse is read the http response body and returns text or error
func GetSeedUrls ¶
func GetTempFile ¶
func IndexFromShardPath ¶
func InitLogging ¶
func InitLogging(filePath string)
InitLogging initializes a rotating logger. This should be done once by the executable filePath is the full path of the log file
func InvalidArgs ¶
func InvalidArgs(msg string)
func IsFullPath ¶
func IsLegalFilePath ¶
IsLegalFilePath checks for forbidden characters
func IsLegalUserName ¶
IsLegalUserName checks for forbidden characters
func MakeFolders ¶
func MakeStringOfLen ¶
func NewArchonHash ¶
NewArchonHash returns the hasher used by Archon code
func NumBytesDisplayString ¶
func PostFromReader ¶
PostFromReader doest a POST to the targetUrl with data from r and reports an error, if any
func PromptForInput ¶
PromptForInput prompts on stdin and reads a line. Empty string is returned on error
func RandomInt64 ¶
func RandomIntFromSlice ¶
func RandomIntRange ¶
RandomIntRange return n random ints in the range 0 to n-1
func RandomStringFromSlice ¶
RandomStringFromSlice returns a random string and removes it from the slice Empty string is returned once the slice is empty
func RawBytesToString ¶
RawBytesToString returns a string without the 0x prefix
func Rewind ¶
func Rewind(r io.ReadSeeker)
func SaveAppConfiguration ¶
func SaveAppConfiguration(config interface{}) error
func SaveConfiguration ¶
func SeparatedStringList ¶
func SetLoggingLevel ¶
func SetLoggingLevel(level LoggingLevel)
func SetLoggingLevelFromName ¶
func SetLoggingLevelFromName(level string)
func StringKeysOf ¶
func StringToBytes ¶
func StringToEthAddress ¶
func ToJsonString ¶
func ToJsonString(data interface{}) string
func UnCompressString ¶
func WaitForCompletion ¶
func WaitForCompletion(repeat, timeout time.Duration, task func() (interface{}, bool)) (interface{}, bool)
WaitForCompletion attempts task at repeat intervals until timeout or success (bool return is true)
func WriteLastLines ¶
WriteLastLines writes the last numLines from filepath to w
func WriteTempFile ¶
WriteTempFile writes from the reader to a temp file and returns the path of the file or an empty string on error
Types ¶
type ArchonHashBytes ¶
type ArchonHashBytes [ArchonHashLen]byte
type ArchonSignature ¶
type ArchonSignature [ArchonSignatureLen]byte
func NewArchonSignature ¶
func NewArchonSignature(sig []byte) *ArchonSignature
func (*ArchonSignature) String ¶
func (a *ArchonSignature) String() string
type ArchonUrl ¶
type ArchonUrl struct { Username string Permission UrlPermission Path string // File path or hash Needed int // Min number of shard needed for reconstruction Total int // Total number of shards to upload }
func NewArchonUrl ¶
NewArchonUrl creates an Archon URL from the string representation
func (*ArchonUrl) DownloadUrl ¶
func (*ArchonUrl) IsWholeFile ¶
func (*ArchonUrl) ShardPaths ¶
type ByteProgress ¶
type ByteProgress struct { Total uint64 // contains filtered or unexported fields }
ByteProgress is needed when aggregating data from code running in parallel
func NewByteProgress ¶
func NewByteProgress(prefix string, total uint64) *ByteProgress
func (*ByteProgress) End ¶
func (bp *ByteProgress) End()
func (*ByteProgress) Progress ¶
func (bp *ByteProgress) Progress(n uint64)
func (*ByteProgress) SetPrefix ¶
func (bp *ByteProgress) SetPrefix(pref string)
type ContainsEpResponse ¶
type ContainsEpResponse struct {
ShardIdx []int `json:"shards"`
}
func NewContainsEpResponse ¶
func NewContainsEpResponse(jsonData []byte) (*ContainsEpResponse, error)
func (*ContainsEpResponse) String ¶
func (c *ContainsEpResponse) String() string
type EthAddress ¶
func NewEthAddress ¶
func NewEthAddress(a []byte) *EthAddress
type HashingWriter ¶
HashingWriter writes streams to both a ToData destination and the ToHash hasher
func NewHashingWriter ¶
func NewHashingWriter(w io.Writer) *HashingWriter
func (*HashingWriter) GetHash ¶
func (w *HashingWriter) GetHash() []byte
type LoggingLevel ¶
type LoggingLevel int
const ( LogLevelUnknown LoggingLevel = iota LogLevelTrace LogLevelDebug LogLevelInfo LogLevelWarning LogLevelError )
func GetLoggingLevel ¶
func GetLoggingLevel() LoggingLevel
func (LoggingLevel) String ¶
func (l LoggingLevel) String() string
type ProgressWriter ¶
type ProgressWriter struct {
Progress *ByteProgress
}
ProgressWriter counts the number of bytes written to it. It implements to the io.Reader interface and we can pass this into io.TeeReader() which will report progress on each Read cycle.
type RetrieveResponse ¶
type RetrieveResponse struct { ArchonUrl string `json:"archon_url"` // Map from shard index to urls storing it Urls map[int][]string `json:"urls"` }
func NewRetrieveResponse ¶
func NewRetrieveResponse(jsonData []byte) (*RetrieveResponse, error)
func (*RetrieveResponse) String ¶
func (r *RetrieveResponse) String() string
type SpProfile ¶
type SpProfile struct { Urls Urls `json:"urls"` // The following for permissioned only Address string `json:"address"` // blockchain address // in the currency of the layer, per MByte per month // (for Eth: Wei/MByte, for Neo: Gas/MByte) MinAskPrice int64 `json:"min_ask"` AvailableGigaBytes float64 `json:"available_giga_bytes"` PledgedGigaBytes float64 `json:"pledged_giga_bytes"` NodeId string `json:"node_id"` }
func (*SpProfile) AddressBytes ¶
type SpProfilesResponse ¶
func NewSpProfilesResponse ¶
func NewSpProfilesResponse(jsonData string) (*SpProfilesResponse, error)
func (*SpProfilesResponse) String ¶
func (r *SpProfilesResponse) String() string
type StorageProviders ¶
type StorageProviders []SpProfile
func NewStorageProviders ¶
func NewStorageProviders(num int) StorageProviders
func (*StorageProviders) Add ¶
func (sps *StorageProviders) Add(sp *SpProfile)
func (*StorageProviders) Addresses ¶
func (sps *StorageProviders) Addresses() (addr []string)
func (*StorageProviders) EthAddresses ¶
func (sps *StorageProviders) EthAddresses() [][ecommon.AddressLength]byte
func (*StorageProviders) ForAllProfiles ¶
func (sps *StorageProviders) ForAllProfiles(do func(*SpProfile))
func (*StorageProviders) Get ¶
func (sps *StorageProviders) Get(i int) *SpProfile
func (*StorageProviders) GetOfAddress ¶
func (sps *StorageProviders) GetOfAddress(addr string) *SpProfile
func (*StorageProviders) Hosts ¶
func (sps *StorageProviders) Hosts() (hosts []string)
func (*StorageProviders) KeepOnly ¶
func (sps *StorageProviders) KeepOnly(n int)
func (*StorageProviders) Num ¶
func (sps *StorageProviders) Num() int
func (*StorageProviders) PickRandom ¶
func (sps *StorageProviders) PickRandom(needed int) StorageProviders
pickRandom returns up to needed random SPs from input sps
func (*StorageProviders) PriceOfUpload ¶
func (sps *StorageProviders) PriceOfUpload(numBytes int64) (totalPrice int64)
in currency of MinAskPrice, which depends on the blockchain for Eth it is Wei, for Neo it is Gas(int8)
func (*StorageProviders) Remove ¶
func (sps *StorageProviders) Remove(removeThis func(profile *SpProfile) bool)
func (*StorageProviders) Set ¶
func (sps *StorageProviders) Set(i int, sp *SpProfile)
func (*StorageProviders) SortByMinAsk ¶
func (sps *StorageProviders) SortByMinAsk(granularity uint64)
Sort by min ask price
type TransactionHash ¶
type TransactionHash [32]byte
Ethereum transaction
func NewTransactionHash ¶
func NewTransactionHash(txHashString string) *TransactionHash
type UrlPermission ¶
type UrlPermission string
const ( Eth UrlPermission = "eth" Neo UrlPermission = "neo" )