Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions code/go/0chain.net/blobber/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,32 @@ import (
)

var (
deploymentMode int
keysFile string
keysFileRaw string
mountPoint string
metadataDB string
logDir string
httpPort int
hostname string
configDir string
grpcPort int
httpsPort int
httpsKeyFile string
httpsCertFile string
hostUrl string
deploymentMode int
keysFile string
keysFilePublicKey string
keysFilePrivateKey string
keysFileClientKey string
keysFileIsSplit bool
mountPoint string
metadataDB string
logDir string
httpPort int
hostname string
configDir string
grpcPort int
httpsPort int
httpsKeyFile string
httpsCertFile string
hostUrl string
)

func init() {
flag.IntVar(&deploymentMode, "deployment_mode", 2, "deployment mode: 0=dev,1=test, 2=mainnet")
flag.StringVar(&keysFile, "keys_file", "", "keys_file")
flag.StringVar(&keysFileRaw, "keys_file_raw", "", "keys_file_raw")
flag.StringVar(&keysFilePublicKey, "keys_file_public_key", "", "keys_file_public_key")
flag.StringVar(&keysFilePrivateKey, "keys_file_private_key", "", "keys_file_private_key")
flag.StringVar(&keysFileClientKey, "keys_file_client_key", "", "keys_file_client_key")
flag.BoolVar(&keysFileIsSplit, "keys_file_is_split", false, "keys_file_is_split")
flag.StringVar(&mountPoint, "files_dir", "", "Mounted partition where all files will be stored")
flag.StringVar(&metadataDB, "db_dir", "", "db_dir")
flag.StringVar(&logDir, "log_dir", "", "log_dir")
Expand Down
14 changes: 10 additions & 4 deletions code/go/0chain.net/blobber/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@ import (
"go.uber.org/zap"
)

var publicKey, privateKey string
var clientKey, publicKey, privateKey string

func setupNode() error {
fmt.Println("> setup blobber")

var err error

if keysFileRaw != "" {
err = readKeysFromString(&keysFileRaw)
if keysFilePrivateKey != "" || keysFilePublicKey != "" {
privateKey = keysFilePrivateKey
publicKey = keysFilePublicKey

if keysFileIsSplit {
clientKey = keysFileClientKey
}

fmt.Println("using blobber keys from local string")
} else {
Expand All @@ -38,7 +43,8 @@ func setupNode() error {
}
}

node.Self.SetKeys(publicKey, privateKey)
node.Self.SetKeys(clientKey, publicKey, privateKey, keysFileIsSplit)

if node.Self.ID == "" {
return errors.New("node definition for self node doesn't exist")
} else {
Expand Down
4 changes: 4 additions & 0 deletions code/go/0chain.net/blobber/zcn.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func setupServerChain() error {
return err
}

if node.Self.GetWallet().IsSplit {
zcncore.RegisterZauthServer(serverChain.ZauthServer)
}

fmt.Print(" [OK]\n")
return nil
}
3 changes: 2 additions & 1 deletion code/go/0chain.net/blobbercore/handler/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package handler
import (
"context"
"errors"
"sync"

"github.com/0chain/gosdk/core/client"
coreTxn "github.com/0chain/gosdk/core/transaction"
"sync"

"github.com/0chain/blobber/code/go/0chain.net/blobbercore/allocation"
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/config"
Expand Down
1 change: 1 addition & 0 deletions code/go/0chain.net/core/chain/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func NewChainFromConfig() *Chain {
chain.ID = common.ToKey(config.Configuration.ChainID)
chain.OwnerID = viper.GetString("server_chain.owner")
chain.BlockWorker = viper.GetString("block_worker")
chain.ZauthServer = viper.GetString("zauth_server")
return chain
}

Expand Down
32 changes: 28 additions & 4 deletions code/go/0chain.net/core/node/self_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"

"github.com/0chain/blobber/code/go/0chain.net/core/common"
"github.com/0chain/blobber/code/go/0chain.net/core/config"
"github.com/0chain/gosdk/core/zcncrypto"
Expand All @@ -19,20 +20,43 @@ type SelfNode struct {
}

/*SetKeys - setter */
func (sn *SelfNode) SetKeys(publicKey, privateKey string) {
publicKeyBytes, err := hex.DecodeString(publicKey)
func (sn *SelfNode) SetKeys(clientKey, publicKey, privateKey string, isSplit bool) {
var (
publicKeyBytes []byte
err error
)

if isSplit {
publicKeyBytes, err = hex.DecodeString(clientKey)
} else {
publicKeyBytes, err = hex.DecodeString(publicKey)
}

if err != nil {
panic(err)
}

sn.wallet = &zcncrypto.Wallet{}
sn.wallet.ClientID = Hash(publicKeyBytes)
sn.wallet.ClientKey = publicKey

if isSplit {
sn.wallet.ClientKey = clientKey
} else {
sn.wallet.ClientKey = publicKey
}

sn.wallet.Keys = make([]zcncrypto.KeyPair, 1)
sn.wallet.Keys[0].PublicKey = publicKey
sn.wallet.Keys[0].PrivateKey = privateKey
sn.wallet.Version = zcncrypto.CryptoVersion
sn.wallet.IsSplit = isSplit

if isSplit {
sn.PublicKey = clientKey
} else {
sn.PublicKey = publicKey
}

sn.PublicKey = publicKey
sn.ID = sn.wallet.ClientID
}

Expand Down
2 changes: 1 addition & 1 deletion code/go/0chain.net/validator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func main() {
fmt.Println("using validator keys from aws")
}

node.Self.SetKeys(publicKey, privateKey)
node.Self.SetKeys("", publicKey, privateKey, false)

if len(*hostUrl) > 0 {
node.Self.URL = *hostUrl
Expand Down
2 changes: 1 addition & 1 deletion code/go/0chain.net/validatorcore/storage/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,6 @@ func setupModelsTest(t *testing.T) error {
return err
}

node.Self.SetKeys(wallet.Keys[0].PublicKey, wallet.Keys[0].PrivateKey)
node.Self.SetKeys("", wallet.Keys[0].PublicKey, wallet.Keys[0].PrivateKey, false)
return nil
}
2 changes: 2 additions & 0 deletions config/0chain_blobber.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ min_confirmation: 10

block_worker: https://dev.0chain.net/dns

zauth_server: https://zauth.dev.0chain.net/

rate_limiters:
# Rate limiters will use this duration to clean unused token buckets.
# If it is 0 then token will expire in 10 years.
Expand Down
Loading