Skip to content
Snippets Groups Projects
Select Git revision
  • 24eb354b1d6fd83d63447e6d4dbcfd5d9fed8fb1
  • release default protected
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • hotfix/TestHostPool_UpdateNdf_AddFilter
  • XX-4719/announcementChannels
  • xx-4717/logLevel
  • jonah/noob-channel
  • master protected
  • XX-4707/tagDiskJson
  • xx-4698/notification-retry
  • hotfix/notifylockup
  • syncNodes
  • hotfix/localCB
  • XX-4677/NewChanManagerMobile
  • XX-4689/DmSync
  • duplicatePrefix
  • XX-4601/HavenInvites
  • finalizedUICallbacks
  • XX-4673/AdminKeySync
  • debugNotifID
  • anne/test
  • v4.7.5
  • v4.7.4
  • v4.7.3
  • v4.7.2
  • v4.7.1
  • v4.6.3
  • v4.6.1
  • v4.5.0
  • v4.4.4
  • v4.3.11
  • v4.3.8
  • v4.3.7
  • v4.3.6
  • v4.3.5
  • v4.2.0
  • v4.3.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
41 results

interface.go

Blame
  • proto.go 2.33 KiB
    ////////////////////////////////////////////////////////////////////////////////
    // Copyright © 2022 xx foundation                                             //
    //                                                                            //
    // Use of this source code is governed by a license that can be found in the  //
    // LICENSE file.                                                              //
    ////////////////////////////////////////////////////////////////////////////////
    
    package cmd
    
    import (
    	"encoding/json"
    	"github.com/pkg/errors"
    	jww "github.com/spf13/jwalterweatherman"
    	"github.com/spf13/viper"
    	"gitlab.com/elixxir/client/storage/user"
    	"gitlab.com/elixxir/client/xxdk"
    	"gitlab.com/xx_network/primitives/utils"
    	"io/fs"
    	"io/ioutil"
    	"os"
    )
    
    // loadOrInitProto will build a new xxdk.E2e from existing storage
    // or from a new storage that it will create if none already exists
    func loadOrInitProto(protoUserPath string, password []byte, storeDir string,
    	cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams, cbs xxdk.AuthCallbacks) *xxdk.E2e {
    	jww.INFO.Printf("Using Proto sender")
    
    	// create a new cMix if none exist
    	if _, err := os.Stat(storeDir); errors.Is(err, fs.ErrNotExist) {
    		// Initialize from scratch
    		ndfJson, err := ioutil.ReadFile(viper.GetString(ndfFlag))
    		if err != nil {
    			jww.FATAL.Panicf("%+v", err)
    		}
    
    		protoUserJson, err := utils.ReadFile(protoUserPath)
    		if err != nil {
    			jww.FATAL.Panicf("%v", err)
    		}
    
    		protoUser := &user.Proto{}
    		err = json.Unmarshal(protoUserJson, protoUser)
    		if err != nil {
    			jww.FATAL.Panicf("%v", err)
    		}
    
    		err = xxdk.NewProtoCmix_Unsafe(string(ndfJson), storeDir,
    			password, protoUser)
    		if err != nil {
    			jww.FATAL.Panicf("%+v", err)
    		}
    	}
    	// Initialize from storage
    	net, err := xxdk.LoadCmix(storeDir, password, cmixParams)
    	if err != nil {
    		jww.FATAL.Panicf("%+v", err)
    	}
    
    	// Load or initialize xxdk.ReceptionIdentity storage
    	identity, err := xxdk.LoadReceptionIdentity(identityStorageKey, net)
    	if err != nil {
    		identity, err = xxdk.MakeLegacyReceptionIdentity(net)
    		if err != nil {
    			jww.FATAL.Panicf("%+v", err)
    		}
    
    		err = xxdk.StoreReceptionIdentity(identityStorageKey, identity, net)
    		if err != nil {
    			jww.FATAL.Panicf("%+v", err)
    		}
    	}
    
    	user, err := xxdk.Login(net, cbs, identity, e2eParams)
    	if err != nil {
    		jww.FATAL.Panicf("%+v", err)
    	}
    	return user
    }