badgegenerator

package
v1.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 45 Imported by: 0

README

Bade generator

How to run

  • please also specify these env variables
       BADGE_DEFAULT_GEOLOCATION: 1
       BADGE_USER_DATA: "{\"1\":{\"default\":{\"project_public_key\":\"test111111\",\"private_key\":\"123456\",\"epochs_max_cu\":1},\"projectId2\":{\"project_public_key\":\"test1122\",\"private_key\":\"12345678\",\"epochs_max_cu\":1}},\"2\":{\"default\":{\"project_public_key\":\"test123\",\"private_key\":\"123456\",\"epochs_max_cu\":1}}}"
       BADGE_COUNTRIES_FILE_PATH: "countries.csv"
       BADGE_IP_FILE_PATH: "ip2asn-v4.tsv"
    
  • run the command
    lavad badgegenerator --port=8080 --log_level=debug  --chain-id=lava  --grpc-url=127.0.0.1:9090
    

Env Variables explained

  1. BADGE_DEFAULT_GEOLOCATION

    this is really important because if for some reason we don't find which country the users is calling from than we use the default value. this value should be on the BADGE_USER_DATA json.

  2. BADGE_COUNTRIES_FILE_PATH

    this is a csv file with all countries and lava-geolocation link for example. It contains four colums country-code;country-name,continent code,lava-geolocation
    for example:

    AD;Andorra;EU;2
    AE;United Arab Emirates;AS;2
    AF;Afghanistan;AS;2
    AL;Albania;EU;2
    AM;Armenia;AS;2
    AO;Angola;AF;2
    
  3. BADGE_IP_FILE_PATH

    this is a tsv file with all ip ranges and country code that they belong. it can be downloaded from here ip pls download ip2asn-v4.tsv It contains 4/5 colums range_start;range_end;AS_number;country_code AS_description
    for example:

    1.0.0.0 1.0.0.255	13335	US	CLOUDFLARENET
    1.0.1.0	1.0.3.255	0	None	Not routed
    1.0.4.0	1.0.5.255	38803	AU	WPL-AS-AP Wirefreebroadband Pty Ltd
    1.0.6.0	1.0.7.255	38803	AU	WPL-AS-AP Wirefreebroadband Pty Ltd
    1.0.8.0	1.0.15.255	0	None	Not routed
    
  4. BADGE_USER_DATA

    a json that link geolocation, public key of a project and private key to use for the encryption.

    {
      "1": {
        "default": {
          "project_public_key": "test111111",
          "private_key": "123456",
          "epochs_max_cu": 1
        },
        "projectId2": {
          "project_public_key": "test1122",
          "private_key": "12345678",
          "epochs_max_cu": 1
        }
      },
      "2": {
        "default": {
          "project_public_key": "test123",
          "private_key": "123456",
          "epochs_max_cu": 1
        }
      }
    }
    

Documentation

Index

Constants

View Source
const (
	PortEnvironmentVariable               = "PORT"
	MetricsPortEnvironmentVariable        = "METRICS_PORT"
	UserDataEnvironmentVariable           = "USER_DATA"
	GrpcUrlEnvironmentVariable            = "GRPC_URL"
	LavaChainIDEnvironmentVariable        = "CHAIN_ID"
	DefaultGeolocationEnvironmentVariable = "DEFAULT_GEOLOCATION"
	CountriesFilePathEnvironmentVariable  = "COUNTRIES_FILE_PATH"
	IpFilePathEnvironmentVariable         = "IP_FILE_PATH"
)
View Source
const AddBlockDelayForEpochUpdaterBadgeServer = 2

adding 3 blocks delay, to update the epoch. the reason is for the sdk to wait until all providers are synced to the new epoch before SDK gets a new pairing list.

View Source
const DefaultProjectId = "default"
View Source
const RefererHeaderKey = "Referer"

Variables

This section is empty.

Functions

func CreateBadgeGeneratorCobraCommand

func CreateBadgeGeneratorCobraCommand() *cobra.Command

func RunBadgeServer

func RunBadgeServer(cmd *cobra.Command, v *viper.Viper)

Types

type BadgeStateTracker

type BadgeStateTracker struct {
	*statetracker.StateTracker
	statetracker.ConsumerEmergencyTrackerInf
	// contains filtered or unexported fields
}

func NewBadgeStateTracker

func NewBadgeStateTracker(ctx context.Context, clientCtx cosmosclient.Context, chainFetcher chaintracker.ChainFetcher, chainId string) (ret *BadgeStateTracker, err error)

func (*BadgeStateTracker) RegisterForDowntimeParamsUpdates

func (st *BadgeStateTracker) RegisterForDowntimeParamsUpdates(ctx context.Context, downtimeParamsUpdatable updaters.DowntimeParamsUpdatable) error

func (*BadgeStateTracker) RegisterForEpochUpdates

func (st *BadgeStateTracker) RegisterForEpochUpdates(ctx context.Context, epochUpdatable updaters.EpochUpdatable)

func (*BadgeStateTracker) RegisterForSpecUpdates

func (st *BadgeStateTracker) RegisterForSpecUpdates(ctx context.Context, specUpdatable updaters.SpecUpdatable, endpoint lavasession.RPCEndpoint) error

type HealthServer

type HealthServer struct {
	health.UnimplementedHealthServer
}

func (*HealthServer) Check

func (*HealthServer) Watch

type IpData

type IpData struct {
	FromIp      int64
	ToIP        int64
	CountryCode string
	Geolocation int
}

type IpService

type IpService struct {
	DefaultGeolocation int
	CountryCsvFilePath string
	IpTsvFilePath      string
	IpCountryData      *[]*IpData
}

func InitIpService

func InitIpService(defaultGeolocation int, countriesFilePath, ipFilePath string) (*IpService, error)

func (*IpService) ReadIpTsvFileData

func (service *IpService) ReadIpTsvFileData() error

func (*IpService) SearchForIp

func (service *IpService) SearchForIp(toSearchIp string) (*IpData, error)

type MetricsService

type MetricsService struct {
	TotalRequests      prometheus.Counter
	FailedRequests     prometheus.Counter
	SuccessfulRequests prometheus.Counter
}

func InitMetrics

func InitMetrics() *MetricsService

func (*MetricsService) AddRequest

func (service *MetricsService) AddRequest(isSuccessful bool)

type ProjectConfiguration

type ProjectConfiguration struct {
	ProjectPublicKey  string                                    `json:"project_public_key"`
	ProjectPrivateKey string                                    `json:"private_key"`
	EpochsMaxCu       int64                                     `json:"epochs_max_cu"`
	UpdatedEpoch      map[string]uint64                         `json:"update_epoch,omitempty"`
	PairingList       map[string]*types.QueryGetPairingResponse `json:"pairing_list,omitempty"`
}

type Server

type Server struct {
	pairingtypes.UnimplementedBadgeGeneratorServer
	ProjectsConfiguration map[string]map[string]*ProjectConfiguration // geolocation/project_id/project_data

	ChainId   string
	IpService *IpService
	// contains filtered or unexported fields
}

func NewServer

func NewServer(ipService *IpService, grpcUrl, chainId, userData string) (*Server, error)

func (*Server) Active

func (s *Server) Active() bool

func (*Server) GetEpoch

func (s *Server) GetEpoch() uint64

func (*Server) GetUniqueName

func (s *Server) GetUniqueName() string

func (*Server) InitializeStateTracker

func (s *Server) InitializeStateTracker(tracker *BadgeStateTracker)

func (*Server) SetSpec

func (s *Server) SetSpec(specUpdate spectypes.Spec)

func (*Server) UpdateEpoch

func (s *Server) UpdateEpoch(epoch uint64)

type UserBadgeItem

type UserBadgeItem struct {
	AllowedCu int64
	Epoch     uint64
	Signature string
	PublicKey string
	UserId    string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL