2016-07-01 03:18:55 +00:00
|
|
|
package core
|
|
|
|
|
2016-10-16 00:04:19 +00:00
|
|
|
import (
|
|
|
|
cryptorand "crypto/rand"
|
|
|
|
"log"
|
|
|
|
"math"
|
|
|
|
"math/big"
|
|
|
|
"math/rand"
|
|
|
|
)
|
|
|
|
|
2016-09-11 04:57:54 +00:00
|
|
|
type Ricochet struct {
|
|
|
|
Config *Config
|
|
|
|
Network *Network
|
|
|
|
Identity *Identity
|
|
|
|
}
|
|
|
|
|
|
|
|
func (core *Ricochet) Init(conf *Config) error {
|
2016-10-16 00:04:19 +00:00
|
|
|
initRand()
|
|
|
|
|
2016-09-11 04:57:54 +00:00
|
|
|
var err error
|
|
|
|
core.Config = conf
|
|
|
|
core.Network = CreateNetwork()
|
|
|
|
core.Identity, err = CreateIdentity(core)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2016-07-01 03:18:55 +00:00
|
|
|
}
|
2016-10-16 00:04:19 +00:00
|
|
|
|
|
|
|
func initRand() {
|
|
|
|
n, err := cryptorand.Int(cryptorand.Reader, big.NewInt(math.MaxInt64))
|
|
|
|
if err != nil {
|
|
|
|
log.Panicf("rng failed: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
rand.Seed(n.Int64())
|
|
|
|
}
|