Documentation ¶
Index ¶
- Constants
- type BatchSanitizer
- type Config
- type Controller
- type Db
- func (db *Db) ActiveTopology(reputationThreshold int64) models.Topology
- func (db *Db) AddMixStatus(status models.PersistedMixStatus)
- func (db *Db) BatchAddMixStatus(status []models.PersistedMixStatus)
- func (db *Db) BatchLoadReports(pubkeys []string) models.BatchMixStatusReport
- func (db *Db) BatchUpdateReputation(reputationChangeMap map[string]int64)
- func (db *Db) GetNMostRecentMixStatuses(pubkey string, ipVersion string, n int) []models.PersistedMixStatus
- func (db *Db) GetNodeMixHost(pubkey string) string
- func (db *Db) IpExists(ip string) bool
- func (db *Db) ListMixStatus(pubkey string, limit int) []models.PersistedMixStatus
- func (db *Db) ListMixStatusDateRange(pubkey string, ipVersion string, start int64, end int64) []models.PersistedMixStatus
- func (db *Db) ListMixStatusSinceWithLimit(pubkey string, ipVersion string, since int64, limit int) []models.PersistedMixStatus
- func (db *Db) LoadNonStaleReports() models.BatchMixStatusReport
- func (db *Db) LoadReport(pubkey string) models.MixStatusReport
- func (db *Db) RegisterGateway(gateway models.RegisteredGateway)
- func (db *Db) RegisterMix(mix models.RegisteredMix)
- func (db *Db) RemoveOldStatuses(before int64)
- func (db *Db) SaveBatchMixStatusReport(report models.BatchMixStatusReport)
- func (db *Db) SaveMixStatusReport(report models.MixStatusReport)
- func (db *Db) SetReputation(id string, newRep int64) bool
- func (db *Db) Topology() models.Topology
- func (db *Db) UnregisterNode(id string) bool
- func (db *Db) UpdateReputation(id string, repIncrease int64) bool
- type GenericSanitizer
- type IDb
- type IService
- type Sanitizer
- type Service
- func (service *Service) BatchCreateMixStatus(batchMixStatus models.BatchMixStatus) []models.PersistedMixStatus
- func (service *Service) BatchGetMixStatusReport() models.BatchMixStatusReport
- func (service *Service) CalculateUptime(pubkey string, ipVersion string, numReports int) int
- func (service *Service) CalculateUptimeSince(pubkey string, ipVersion string, since int64, numReports int) int
- func (service *Service) CheckForDuplicateIP(host string) bool
- func (service *Service) CreateMixStatus(mixStatus models.MixStatus) models.PersistedMixStatus
- func (service *Service) GatewayCount() int
- func (service *Service) GetStatusReport(pubkey string) models.MixStatusReport
- func (service *Service) ListMixStatus(pubkey string) []models.PersistedMixStatus
- func (service *Service) MixCount() int
- func (service *Service) SaveBatchStatusReport(status []models.PersistedMixStatus) models.BatchMixStatusReport
- func (service *Service) SaveStatusReport(status models.PersistedMixStatus) models.MixStatusReport
- func (service *Service) StartupPurge()
Constants ¶
const Last5MinutesReports = 5
const LastDayReports = 1000
const LastHourReports = 50
const MaximumGateways = 1000
explicitly declared so that a similar attack could not be used for gateways this time.
const MaximumMixnodes = 1500
const ReportFailureReputationDecrease = int64(-2)
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
const ReputationThreshold = int64(100)
const SystemVersion = "0.9.2"
const TopologyCacheTTL = time.Second * 30
const TopologyNotRefreshing = 0
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 ¶
Controller ...
type Db ¶
type Db struct {
// contains filtered or unexported fields
}
Db is a hashtable that holds mixnode uptime mixmining
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) 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) 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 ¶
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) UnregisterNode ¶
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 ¶
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 (*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 ¶
CalculateUptime calculates percentage uptime for a given node, protocol since a specific time
func (*Service) CalculateUptimeSince ¶
func (*Service) CheckForDuplicateIP ¶
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) 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) 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