Documentation ¶
Overview ¶
Copyright 2020 PhysarumSM Development Team * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
Copyright 2020 PhysarumSM Development Team * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
Index ¶
- Constants
- func AddBootstrapFlags() (*[]multiaddr.Multiaddr, error)
- func AddPSKFlag() (*pnet.PSK, error)
- func CreateOrLoadKey(kf KeyFlags) (crypto.PrivKey, error)
- func CreatePSK(psk string) (pnet.PSK, error)
- func CreateRandPSK() (pnet.PSK, error)
- func ExpandTilde(path string) (string, error)
- func FileExists(filePath string) bool
- func GeneratePrivKey(algo string, bits int) (crypto.PrivKey, error)
- func GetBootstrapPointer() *bootstrapAddrs
- func GetEnvBootstraps() ([]multiaddr.Multiaddr, error)
- func GetEnvPSK() (pnet.PSK, error)
- func GetEnvPSKString() string
- func GetFlagPSKString() string
- func GetFreePort() (int, error)
- func GetIPAddress() (string, error)
- func GetPSKPointer() *pskValue
- func IpfsHashBytes(data []byte) (hash string, err error)
- func IpfsHashFile(path string) (hash string, err error)
- func LoadPrivKeyFromFile(keyFile string) (crypto.PrivKey, error)
- func StorePrivKeyToFile(priv crypto.PrivKey, keyFile string) error
- func StringsToMultiaddrs(stringMultiaddrs []string) ([]multiaddr.Multiaddr, error)
- func Whoami(node host.Host) ([]multiaddr.Multiaddr, error)
- type ExpoBackoff
- type ExpoBackoffAttempts
- type KeyFlags
Constants ¶
const ( // libp2p's PSK definition is a slice of 32 bytes PSK_NUM_BYTES = 32 ENV_KEY_PSK = "P2P_PSK" )
const ENV_KEY_BOOTSTRAPS = "P2P_BOOTSTRAPS"
const (
RSA_MIN_BITS = 2048
)
Variables ¶
This section is empty.
Functions ¶
func AddBootstrapFlags ¶
func AddBootstrapFlags() (*[]multiaddr.Multiaddr, error)
Returns address to a slice of strings that will store the bootstrap multiaddresses once flag.Parse() is called (prior to that, it will be an empty slice).
func AddPSKFlag ¶
Sets the "-psk" flag and returns a pointer to a pre-shared key
func CreatePSK ¶
Uses SHA256 to hash an input string into a 256-bit value. This matches libp2p's current implementation for PSK, which seems to be hard-coded to be 32 Bytes (256 bits) long.
If the input string is the zero-value (i.e. ""), then this function call is equivalent to calling CreateRandPSK(), which generates a random pre-shared key.
func ExpandTilde ¶
Expands tilde to absolute path Currently only works if path begins with tilde, not somewhere in the middle
func FileExists ¶
func GetBootstrapPointer ¶
func GetBootstrapPointer() *bootstrapAddrs
Don't like this... feels hacky to have a function just for tests in the main package This is needed to return a pointer to type bootstrapAddrs, a hidden type. This enables tests for the Set() and String() functions above.
func GetEnvBootstraps ¶
func GetEnvBootstraps() ([]multiaddr.Multiaddr, error)
If the environment variable does not exist, or if there are errors during parsing, return the 0-value of the return type.
func GetEnvPSK ¶
If the environment variable does not exist, or if there are errors during parsing, return the 0-value of the return type.
func GetEnvPSKString ¶
func GetEnvPSKString() string
Returns un-hashed PSK passphrase specified in environment variable
func GetFlagPSKString ¶
func GetFlagPSKString() string
Returns the un-hashed PSK passphrase of the PSK from the last time Get() was called.
func GetPSKPointer ¶
func GetPSKPointer() *pskValue
For enabling tests, ideally should not be used. This is needed to return a pointer to type pskValue, a hidden type. This enables tests for the Set() and String() functions above.
func IpfsHashBytes ¶
func IpfsHashFile ¶
func LoadPrivKeyFromFile ¶
Inverse of storePrivKeyToFile()
func StorePrivKeyToFile ¶
Write private key to file in Base 64 format Store the key type ID followed by a space, then the key, then a new-line
func StringsToMultiaddrs ¶
Helper function to cast a slice of strings into a slice of Multiaddrs
Types ¶
type ExpoBackoff ¶
type ExpoBackoff struct {
// contains filtered or unexported fields
}
func NewExpoBackoff ¶
func NewExpoBackoff(init, max time.Duration) (*ExpoBackoff, error)
Creates a new ExpoBackoff. Parameters 'init' and 'max' denote initial and max durations to sleep whenever the Sleep() method is called.
func (*ExpoBackoff) Sleep ¶
func (eb *ExpoBackoff) Sleep()
Sleeps for some duration, where each invocation of this method will exponentially increasing the duration.
type ExpoBackoffAttempts ¶
type ExpoBackoffAttempts struct {
// contains filtered or unexported fields
}
func NewExpoBackoffAttempts ¶
func NewExpoBackoffAttempts(init, max time.Duration, attempts int) (*ExpoBackoffAttempts, error)
Creates a new ExpoBackoffAttempts Similar to ExpoBackoff, but limited in the number of times it can sleep See example usage in comments for the Attempt() method
func (*ExpoBackoffAttempts) Attempt ¶
func (eba *ExpoBackoffAttempts) Attempt() bool
Wrapper function around ExponentialBackoff's Sleep(). Allows users to write for loops such as:
eba := NewExpoBackoffAttempts(1 * time.Second, 8 * time.Second, 6) for eba.Attempt() { // DO SOMETHING }
The above loop will execute 6 times, and sleep 5 times (1, 2, 4, 8, and 8 seconds) between loops. Note that the first call will not sleep.
Returns
- False: If max attempts has been reached
- True: If max attempts has not been reached, will return true after potentially sleeping. Note that the first call will not sleep.
type KeyFlags ¶
func AddKeyFlags ¶
Adds CLI arguments for key-related flags. Does not call Parse() on its own.
Takes a single parameter, the default key filename. This allows programs to define different default key filenames, so that if two different programs are run on the same host, they won't read from the same key.
Returns a struct containing pointers to the various variables that will hold the parsed flag values once Parse() is called.