mixmining

package
v0.10.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const Last5MinutesReports = 5
View Source
const LastDayReports = 1000
View Source
const LastHourReports = 50
View Source
const MaximumGateways = 1000

explicitly declared so that a similar attack could not be used for gateways this time.

View Source
const MaximumMixnodes = 1500
View Source
const ReportFailureReputationDecrease = int64(-2)
View Source
const ReportSuccessReputationIncrease = int64(3)

so if you can mix ipv4 but not ipv6, your reputation will go down but not as fast as if you didn't mix at all

View Source
const ReputationThreshold = int64(100)
View Source
const SystemVersion = "0.9.2"
View Source
const TopologyCacheTTL = time.Second * 30
View Source
const TopologyNotRefreshing = 0
View Source
const TopologyRefreshing = 1

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchSanitizer

type BatchSanitizer interface {
	Sanitize(input models.BatchMixStatus) models.BatchMixStatus
}

BatchSanitizer sanitizes untrusted batch mixmining data. It should be used in controllers to wipe out any questionable input at our application's front door.

func NewBatchSanitizer

func NewBatchSanitizer(policy *bluemonday.Policy) BatchSanitizer

NewBatchSanitizer returns a new input sanitizer for metrics

type Config

type Config struct {
	BatchSanitizer   BatchSanitizer   // batch mix reports
	GenericSanitizer GenericSanitizer // originally introduced for what was in mix registration
	Sanitizer        Sanitizer        // mix reports
	Service          IService
}

Config for this controller

type Controller

type Controller interface {
	CreateMixStatus(c *gin.Context)
	RegisterRoutes(router *gin.Engine)
}

Controller ...

func New

func New(cfg Config) Controller

New returns a new mixmining.Controller

type Db

type Db struct {
	// contains filtered or unexported fields
}

Db is a hashtable that holds mixnode uptime mixmining

func NewDb

func NewDb(isTest bool) *Db

NewDb constructor

func (*Db) ActiveTopology

func (db *Db) ActiveTopology(reputationThreshold int64) models.Topology

func (*Db) AddMixStatus

func (db *Db) AddMixStatus(status models.PersistedMixStatus)

Add saves a PersistedMixStatus

func (*Db) BatchAddMixStatus

func (db *Db) BatchAddMixStatus(status []models.PersistedMixStatus)

BatchAdd saves multiple PersistedMixStatus

func (*Db) BatchLoadReports

func (db *Db) BatchLoadReports(pubkeys []string) models.BatchMixStatusReport

BatchLoadReports retrieves a models.BatchMixStatusReport based on provided set of public keys. If a report isn't found, it crudely generates a new instance and returns that instead.

func (*Db) BatchUpdateReputation

func (db *Db) BatchUpdateReputation(reputationChangeMap map[string]int64)

func (*Db) GetNMostRecentMixStatuses

func (db *Db) GetNMostRecentMixStatuses(pubkey string, ipVersion string, n int) []models.PersistedMixStatus

GetNMostRecentMixStatus lists `n` most recent persisted mix statuses for a node for either IPv4 or IPv6

func (*Db) GetNodeMixHost

func (db *Db) GetNodeMixHost(pubkey string) string

func (*Db) IpExists

func (db *Db) IpExists(ip string) bool

func (*Db) ListMixStatus

func (db *Db) ListMixStatus(pubkey string, limit int) []models.PersistedMixStatus

List returns all models.PersistedMixStatus in the orm

func (*Db) ListMixStatusDateRange

func (db *Db) ListMixStatusDateRange(pubkey string, ipVersion string, start int64, end int64) []models.PersistedMixStatus

ListDateRange lists all persisted mix statuses for a node for either IPv4 or IPv6 within the specified date range

func (*Db) ListMixStatusSinceWithLimit

func (db *Db) ListMixStatusSinceWithLimit(pubkey string, ipVersion string, since int64, limit int) []models.PersistedMixStatus

ListMixStatusSinceWithLimit lists all persisted mix statuses for a node for either IPv4 or IPv6 since the specified timestamp with the maximum of `limit` results

func (*Db) LoadNonStaleReports

func (db *Db) LoadNonStaleReports() models.BatchMixStatusReport

LoadNonStaleReports retrieves a models.BatchMixStatusReport, such that each mixnode in the retrieved report must have been online for over 50% of time in the last day. If a report isn't found, it crudely generates a new instance and returns that instead.

func (*Db) LoadReport

func (db *Db) LoadReport(pubkey string) models.MixStatusReport

LoadReport retrieves a models.MixStatusReport. If a report isn't found, it crudely generates a new instance and returns that instead.

func (*Db) RegisterGateway

func (db *Db) RegisterGateway(gateway models.RegisteredGateway)

func (*Db) RegisterMix

func (db *Db) RegisterMix(mix models.RegisteredMix)

func (*Db) RemoveOldStatuses

func (db *Db) RemoveOldStatuses(before int64)

RemoveOldStatuses removes all `PersistedMixStatus` that were created before the provided timestamp.

func (*Db) SaveBatchMixStatusReport

func (db *Db) SaveBatchMixStatusReport(report models.BatchMixStatusReport)

SaveBatchMixStatusReport creates or updates a status summary report for multiple mixnodex in the database

func (*Db) SaveMixStatusReport

func (db *Db) SaveMixStatusReport(report models.MixStatusReport)

SaveMixStatusReport creates or updates a status summary report for a given mixnode in the database

func (*Db) SetReputation

func (db *Db) SetReputation(id string, newRep int64) bool

func (*Db) Topology

func (db *Db) Topology() models.Topology

func (*Db) UnregisterNode

func (db *Db) UnregisterNode(id string) bool

func (*Db) UpdateReputation

func (db *Db) UpdateReputation(id string, repIncrease int64) bool

type GenericSanitizer

type GenericSanitizer interface {
	Sanitize(input interface{})
}

GenericSanitizer sanitizes untrusted data of any type. It mutates its arguments in place.

func NewGenericSanitizer

func NewGenericSanitizer(policy *bluemonday.Policy) GenericSanitizer

NewSanitizer returns a new input sanitizer for all presence-related things

type IDb

type IDb interface {
	AddMixStatus(models.PersistedMixStatus)
	BatchAddMixStatus(status []models.PersistedMixStatus)
	ListMixStatus(pubkey string, limit int) []models.PersistedMixStatus
	ListMixStatusDateRange(pubkey string, ipVersion string, start int64, end int64) []models.PersistedMixStatus
	LoadReport(pubkey string) models.MixStatusReport
	LoadNonStaleReports() models.BatchMixStatusReport
	BatchLoadReports(pubkeys []string) models.BatchMixStatusReport
	SaveMixStatusReport(models.MixStatusReport)
	SaveBatchMixStatusReport(models.BatchMixStatusReport)

	// moved from 'presence'
	RegisterMix(mix models.RegisteredMix)
	RegisterGateway(gateway models.RegisteredGateway)
	UnregisterNode(id string) bool
	UpdateReputation(id string, repIncrease int64) bool
	BatchUpdateReputation(reputationChangeMap map[string]int64)
	SetReputation(id string, newRep int64) bool
	Topology() models.Topology
	ActiveTopology(reputationThreshold int64) models.Topology

	IpExists(ip string) bool
	GetNMostRecentMixStatuses(pubkey string, ipVersion string, n int) []models.PersistedMixStatus
	ListMixStatusSinceWithLimit(pubkey string, ipVersion string, since int64, limit int) []models.PersistedMixStatus
	RemoveOldStatuses(before int64)
	GetNodeMixHost(pubkey string) string
}

IDb holds status information

type IService

type IService interface {
	CreateMixStatus(mixStatus models.MixStatus) models.PersistedMixStatus
	ListMixStatus(pubkey string) []models.PersistedMixStatus
	SaveStatusReport(status models.PersistedMixStatus) models.MixStatusReport
	GetStatusReport(pubkey string) models.MixStatusReport

	SaveBatchStatusReport(status []models.PersistedMixStatus) models.BatchMixStatusReport
	BatchCreateMixStatus(batchMixStatus models.BatchMixStatus) []models.PersistedMixStatus
	BatchGetMixStatusReport() models.BatchMixStatusReport

	CheckForDuplicateIP(host string) bool
	MixCount() int
	GatewayCount() int
	StartupPurge()
}

IService defines the REST service interface for mixmining.

type Sanitizer

type Sanitizer interface {
	Sanitize(input models.MixStatus) models.MixStatus
}

Sanitizer sanitizes untrusted mixmining data. It should be used in controllers to wipe out any questionable input at our application's front door.

func NewSanitizer

func NewSanitizer(policy *bluemonday.Policy) Sanitizer

NewSanitizer returns a new input sanitizer for metrics

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service struct

func NewService

func NewService(db IDb, isTest bool) *Service

NewService constructor

func (*Service) BatchCreateMixStatus

func (service *Service) BatchCreateMixStatus(batchMixStatus models.BatchMixStatus) []models.PersistedMixStatus

BatchCreateMixStatus batch adds new multiple PersistedMixStatus in the orm.

func (*Service) BatchGetMixStatusReport

func (service *Service) BatchGetMixStatusReport() models.BatchMixStatusReport

BatchGetMixStatusReport gets BatchMixStatusReport which contain multiple MixStatusReport.

func (*Service) CalculateUptime

func (service *Service) CalculateUptime(pubkey string, ipVersion string, numReports int) int

CalculateUptime calculates percentage uptime for a given node, protocol since a specific time

func (*Service) CalculateUptimeSince

func (service *Service) CalculateUptimeSince(pubkey string, ipVersion string, since int64, numReports int) int

func (*Service) CheckForDuplicateIP

func (service *Service) CheckForDuplicateIP(host string) bool

func (*Service) CreateMixStatus

func (service *Service) CreateMixStatus(mixStatus models.MixStatus) models.PersistedMixStatus

CreateMixStatus adds a new PersistedMixStatus in the orm.

func (*Service) GatewayCount

func (service *Service) GatewayCount() int

func (*Service) GetStatusReport

func (service *Service) GetStatusReport(pubkey string) models.MixStatusReport

GetStatusReport gets a single MixStatusReport by node public key

func (*Service) ListMixStatus

func (service *Service) ListMixStatus(pubkey string) []models.PersistedMixStatus

List lists the given number mix metrics

func (*Service) MixCount

func (service *Service) MixCount() int

func (*Service) SaveBatchStatusReport

func (service *Service) SaveBatchStatusReport(status []models.PersistedMixStatus) models.BatchMixStatusReport

SaveBatchStatusReport builds and saves a status report for multiple mixnodes simultaneously. Those reports can be updated once whenever we receive a new status, and the saved results can then be queried. This keeps us from having to build the report dynamically on every request at runtime.

func (*Service) SaveStatusReport

func (service *Service) SaveStatusReport(status models.PersistedMixStatus) models.MixStatusReport

SaveStatusReport builds and saves a status report for a mixnode. The report can be updated once whenever we receive a new status, and the saved result can then be queried. This keeps us from having to build the report dynamically on every request at runtime.

func (*Service) StartupPurge

func (service *Service) StartupPurge()

StartupPurge moves any mixnode from the main topology into 'removed' if it is not running version 0.9.2. The "50%" uptime requirement does not need to be checked here as if it's not fulfilled, the node will be automatically moved to "removed set" on the first run of the network monitor

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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