Skip to content
Snippets Groups Projects
Select Git revision
  • 4a9df9a9b48e5a5b3c21ee355d4ecd482a6b31aa
  • 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

types.go

Blame
  • precan.go 2.30 KiB
    ///////////////////////////////////////////////////////////////////////////////
    // Copyright © 2020 xx network SEZC                                          //
    //                                                                           //
    // Use of this source code is governed by a license that can be found in the //
    // LICENSE file                                                              //
    ///////////////////////////////////////////////////////////////////////////////
    
    // precan.go handles functions for precan users, which are not usable
    // unless you are on a localized test network.
    package cmd
    
    import (
    	"encoding/binary"
    	"gitlab.com/elixxir/client/xxdk"
    	"strconv"
    
    	jww "github.com/spf13/jwalterweatherman"
    	"gitlab.com/elixxir/crypto/contact"
    	"gitlab.com/xx_network/primitives/id"
    )
    
    func isPrecanID(id *id.ID) bool {
    	// check if precanned
    	rBytes := id.Bytes()
    	for i := 0; i < 32; i++ {
    		if i != 7 && rBytes[i] != 0 {
    			return false
    		}
    	}
    	if rBytes[7] != byte(0) && rBytes[7] <= byte(40) {
    		return true
    	}
    	return false
    }
    
    // returns a simple numerical id if the user is a precanned user, otherwise
    // returns the normal string of the userID
    func printIDNice(uid *id.ID) string {
    
    	for index, puid := range precannedIDList {
    		if uid.Cmp(puid) {
    			return strconv.Itoa(index + 1)
    		}
    	}
    
    	return uid.String()
    }
    
    // build a list of precanned ids to use for comparision for nicer user id output
    var precannedIDList = buildPrecannedIDList()
    
    func buildPrecannedIDList() []*id.ID {
    
    	idList := make([]*id.ID, 40)
    
    	for i := 0; i < 40; i++ {
    		uid := new(id.ID)
    		binary.BigEndian.PutUint64(uid[:], uint64(i+1))
    		uid.SetType(id.User)
    		idList[i] = uid
    	}
    
    	return idList
    }
    
    func getPrecanID(recipientID *id.ID) uint {
    	return uint(recipientID.Bytes()[7])
    }
    
    func addPrecanAuthenticatedChannel(client *xxdk.E2e, recipientID *id.ID,
    	recipient contact.Contact) {
    	jww.WARN.Printf("Precanned user id detected: %s", recipientID)
    	preUsr, err := client.MakePrecannedAuthenticatedChannel(
    		getPrecanID(recipientID))
    	if err != nil {
    		jww.FATAL.Panicf("%+v", err)
    	}
    	// Sanity check, make sure user id's haven't changed
    	preBytes := preUsr.ID.Bytes()
    	idBytes := recipientID.Bytes()
    	for i := 0; i < len(preBytes); i++ {
    		if idBytes[i] != preBytes[i] {
    			jww.FATAL.Panicf("no id match: %v %v",
    				preBytes, idBytes)
    		}
    	}
    }