Documentation ¶
Index ¶
- func Base64ToString(encoded string) (string, error)
- func CheckAnnotation(fd *os.File, expected map[Annotation]bool) error
- func DissectFile(fd *os.File, extractor StringExtractor, queue chan QueueUnit)
- func LazyParseRawDescriptor(rawDescriptor string) (string, func() *RouterDescriptor, error)
- func LazyParseRawStatus(rawStatus string) (string, func() *RouterStatus, error)
- func LazyParseRawStatusMicro(rawStatus string) (string, func() *RouterStatus, error)
- func ParseRawDescriptor(rawDescriptor string) (string, func() *RouterDescriptor, error)
- func ParseRawStatus(rawStatus string) (string, func() *RouterStatus, error)
- func ParseRawStatusMicro(rawStatus string) (string, func() *RouterStatus, error)
- func StringToPort(portStr string) uint16
- type Annotation
- type Consensus
- func (c *Consensus) Get(fingerprint string) (*RouterStatus, bool)
- func (a *Consensus) Intersect(b *Consensus) *Consensus
- func (c *Consensus) Length() int
- func (c Consensus) PrintObjects()
- func (c *Consensus) Set(fingerprint string, status *RouterStatus)
- func (a *Consensus) Subtract(b *Consensus) *Consensus
- type ExitPattern
- type ObjectCollector
- type QueueUnit
- type RouterDescriptor
- type RouterDescriptors
- type RouterFlags
- type RouterStatus
- type StringExtractor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Base64ToString ¶
Decodes the given Base64-encoded string and returns the resulting string. If there are errors during decoding, an error string is returned.
func CheckAnnotation ¶
func CheckAnnotation(fd *os.File, expected map[Annotation]bool) error
Checks the type annotation in the given file. The Annotation struct determines what we want to see in the file. If we don't see the expected annotation, an error string is returned.
func DissectFile ¶
func DissectFile(fd *os.File, extractor StringExtractor, queue chan QueueUnit)
Dissects the given file into string chunks by using the given string extraction function. The resulting string chunks are then written to the given queue where the receiving end parses them.
func LazyParseRawDescriptor ¶
func LazyParseRawDescriptor(rawDescriptor string) (string, func() *RouterDescriptor, error)
LazyParseRawDescriptor lazily parses a raw router descriptor (in string format) and returns the descriptor's fingerprint, a function returning the descriptor, and an error if the descriptor could not be parsed. Parsing is delayed until the router descriptor is accessed.
func LazyParseRawStatus ¶
func LazyParseRawStatus(rawStatus string) (string, func() *RouterStatus, error)
LazyParseRawStatus parses a raw router status (in string format) and returns the router's fingerprint, a function which returns a RouterStatus, and an error if there were any during parsing. Parsing of the given string is delayed until the returned function is executed.
func LazyParseRawStatusMicro ¶
func LazyParseRawStatusMicro(rawStatus string) (string, func() *RouterStatus, error)
func ParseRawDescriptor ¶
func ParseRawDescriptor(rawDescriptor string) (string, func() *RouterDescriptor, error)
ParseRawDescriptor parses a raw router descriptor (in string format) and returns the descriptor's fingerprint, a function returning the descriptor, and an error if the descriptor could not be parsed. In contrast to LazyParseRawDescriptor, parsing is *not* delayed.
func ParseRawStatus ¶
func ParseRawStatus(rawStatus string) (string, func() *RouterStatus, error)
ParseRawStatus parses a raw router status (in string format) and returns the router's fingerprint, a function which returns a RouterStatus, and an error if there were any during parsing.
func ParseRawStatusMicro ¶
func ParseRawStatusMicro(rawStatus string) (string, func() *RouterStatus, error)
func StringToPort ¶
Convert the given port string to an unsigned 16-bit integer. If the conversion fails or the number cannot be represented in 16 bits, 0 is returned.
Types ¶
type Annotation ¶
func GetAnnotation ¶
func GetAnnotation(fileName string) (*Annotation, error)
GetAnnotation obtains and returns the given file's annotation. If anything fails in the process, an error string is returned.
func (*Annotation) Equals ¶
func (a *Annotation) Equals(b *Annotation) bool
Equals checks whether the two given annotations have the same content.
func (*Annotation) String ¶
func (a *Annotation) String() string
type Consensus ¶
type Consensus struct { // A map from relay fingerprint to a function which returns the relay // status. RouterStatuses map[string]func() *RouterStatus }
func LazilyParseConsensusFile ¶
LazilyParseConsensusFile parses the given file and returns a network consensus if parsing was successful. If there were any errors, an error string is returned. Parsing of the router statuses is delayed until they are accessed using the Get method. As a result, this function is recommended as long as you won't access more than ~50% of all statuses.
func NewConsensus ¶
func NewConsensus() *Consensus
NewConsensus serves as a constructor and returns a pointer to a freshly allocated and empty Consensus.
func ParseConsensusFile ¶
ParseConsensusFile parses the given file and returns a network consensus if parsing was successful. If there were any errors, an error string is returned. In contrast to LazilyParseConsensusFile, parsing of router statuses is *not* delayed. As a result, this function is recommended as long as you will access most of all statuses.
func ParseMicroConsensusFile ¶
func (*Consensus) Get ¶
func (c *Consensus) Get(fingerprint string) (*RouterStatus, bool)
Get returns the router status for the given fingerprint and a boolean value indicating if the status could be found in the consensus.
func (*Consensus) Intersect ¶
Intersect determines the intersection between the given consensus b and consensus a. It returns a new consensus which is the intersection of both given consensuses.
func (Consensus) PrintObjects ¶
func (c Consensus) PrintObjects()
PrintObjects implements the ObjectCollector interface.
func (*Consensus) Set ¶
func (c *Consensus) Set(fingerprint string, status *RouterStatus)
Set adds a new fingerprint mapping to a function returning the router status to the consensus.
type ExitPattern ¶
An exitpattern as defined in dirspec.txt, Section 2.1.3.
type ObjectCollector ¶
type ObjectCollector interface {
PrintObjects()
}
func ParseUnknownFile ¶
func ParseUnknownFile(fileName string) (ObjectCollector, error)
ParseUnknownFile attempts to parse a file whose content we don't know. We try to use the right parser by looking at the file's annotation. An ObjectCollector is returned if parsing was successful.
type RouterDescriptor ¶
type RouterDescriptor struct { // The single fields of a "router" line. Nickname string Address net.IP ORPort uint16 SOCKSPort uint16 DirPort uint16 // The single fields of a "bandwidth" line. All bandwidth values are in // bytes per second. BandwidthAvg uint64 BandwidthBurst uint64 BandwidthObs uint64 // The single fields of a "platform" line. OperatingSystem string TorVersion string // The single fields of a "published" line. Published time.Time // The single fields of an "uptime" line. Uptime uint64 // The single fields of a "fingerprint" line. Fingerprint string // The single fields of a "hibernating" line. Hibernating bool // The single fields of a "family" line. Family []string // The single fields of a "contact" line. Contact string // The "hidden-service-dir" line. HiddenServiceDir bool OnionKey string NTorOnionKey string SigningKey string Accept []*ExitPattern Reject []*ExitPattern }
An (incomplete) router descriptor as defined in dirspec.txt, Section 2.1.1.
func (RouterDescriptor) String ¶
func (desc RouterDescriptor) String() string
Implement the Stringer interface for pretty printing.
type RouterDescriptors ¶
type RouterDescriptors struct { // A map from relay fingerprint to a function which returns the router // descriptor. RouterDescriptors map[string]func() *RouterDescriptor }
func LazilyParseDescriptorFile ¶
func LazilyParseDescriptorFile(fileName string) (*RouterDescriptors, error)
LazilyParseDescriptorFile parses the given file and returns a pointer to RouterDescriptors containing the router descriptors. If there were any errors, an error string is returned. Note that parsing is done lazily which means that it is delayed until a given router descriptor is accessed. That pays off when you know that you will not parse most router descriptors.
func NewRouterDescriptors ¶
func NewRouterDescriptors() *RouterDescriptors
NewRouterDescriptors serves as a constructor and returns a pointer to a freshly allocated and empty RouterDescriptors struct.
func ParseDescriptorFile ¶
func ParseDescriptorFile(fileName string) (*RouterDescriptors, error)
ParseDescriptorFile parses the given file and returns a pointer to RouterDescriptors containing the router descriptors. If there were any errors, an error string is returned. Note that in contrast to LazilyParseDescriptorFile, parsing is *not* delayed. That pays off when you know that you will parse most router descriptors.
func (*RouterDescriptors) Get ¶
func (d *RouterDescriptors) Get(fingerprint string) (*RouterDescriptor, bool)
Get returns the router descriptor for the given fingerprint and a boolean value indicating if the descriptor could be found.
func (RouterDescriptors) PrintObjects ¶
func (desc RouterDescriptors) PrintObjects()
PrintObjects implements the ObjectCollector interface.
func (*RouterDescriptors) Set ¶
func (d *RouterDescriptors) Set(fingerprint string, descriptor *RouterDescriptor)
Set adds a new fingerprint mapping to a function returning the router descriptor.
type RouterFlags ¶
type RouterFlags struct { Authority bool BadExit bool Exit bool Fast bool Guard bool HSDir bool Named bool Stable bool Running bool Unnamed bool Valid bool V2Dir bool }
func (RouterFlags) String ¶
func (flags RouterFlags) String() string
Implement the Stringer interface for pretty printing.
type RouterStatus ¶
type RouterStatus struct { // The single fields of an "r" line. Nickname string Fingerprint string Digest string Publication time.Time Address net.IP ORPort uint16 DirPort uint16 // The single fields of an "s" line. Flags RouterFlags // The single fields of a "v" line. TorVersion string // The single fields of a "w" line. Bandwidth uint64 Measured uint64 Unmeasured bool // The single fields of a "p" line. Accept bool PortList string // The single fields of a "m" line. MicroDigest string }
func (RouterStatus) String ¶
func (status RouterStatus) String() string
Implement the Stringer interface for pretty printing.