scanner

package
v0.0.0-...-c288277 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2020 License: MIT Imports: 11 Imported by: 0

README

Scanner

Scanner is a concurrent, configurable TCP scanner for OnionTree content.

Example

package main

import (
    "fmt"
    "context"
    "github.com/onionltd/go-oniontree"
    "github.com/onionltd/go-oniontree/scanner"
)

func main() {
    s := scanner.NewScanner(scanner.DefaultScannerConfig)

    eventCh := make(chan scanner.Event)

    go func(){
        if err := s.Start(context.TODO(), ".", eventCh); err != nil {
            panic(err)
        }
    }()

    for {
        select {
        case e := <-eventCh:
            switch event := e.(type) {
            case scanner.ScanEvent:
                fmt.Printf("%+v\n", event)
            }
        }
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultScannerConfig = ScannerConfig{
	WorkerTCPConnectionsMax: 256,
	WorkerConfig:            DefaultWorkerConfig,
}
View Source
var DefaultWorkerConfig = WorkerConfig{
	PingInterval:      1 * time.Minute,
	PingTimeout:       50 * time.Second,
	PingPauseInterval: 5 * time.Minute,
	PingRetryInterval: 10 * time.Second,
	PingRetryAttempts: 3,
}

Functions

func Normalize

func Normalize(u string) (string, error)

func ParseHostPort

func ParseHostPort(u string) (string, error)

Types

type Event

type Event interface{}

type Process

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

func (*Process) Reload

func (p *Process) Reload(ctx context.Context)

func (*Process) Start

func (p *Process) Start(ctx context.Context, serviceID string, outputCh chan<- Event) error

func (*Process) Stop

func (p *Process) Stop()

type ProcessStarted

type ProcessStarted struct {
	ServiceID string
}

type ProcessStopped

type ProcessStopped struct {
	ServiceID string
	Error     error
}

type ScanEvent

type ScanEvent struct {
	Status    Status
	URL       string
	ServiceID string
	Directory string
	Error     error
}

type Scanner

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

func NewScanner

func NewScanner(cfg ScannerConfig) *Scanner

func (*Scanner) Start

func (m *Scanner) Start(ctx context.Context, dir string, outputCh chan<- Event) error

func (*Scanner) Stop

func (m *Scanner) Stop()

type ScannerConfig

type ScannerConfig struct {
	// WorkerConnectionsMax limits number of parallel outbound TCP connections.
	WorkerTCPConnectionsMax int64
	// WorkerConfig is a configuration passed to workers.
	WorkerConfig WorkerConfig
}

type Status

type Status uint8
const (
	StatusOnline  Status = 1
	StatusOffline Status = 0
)

func (Status) String

func (s Status) String() string

type Worker

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

func (*Worker) Start

func (w *Worker) Start(ctx context.Context, url string, outputCh chan<- Event) error

func (*Worker) Stop

func (w *Worker) Stop()

type WorkerConfig

type WorkerConfig struct {
	PingInterval      time.Duration
	PingTimeout       time.Duration
	PingPauseInterval time.Duration
	PingRetryInterval time.Duration
	PingRetryAttempts int
}

type WorkerStarted

type WorkerStarted struct {
	URL       string
	ServiceID string
}

type WorkerStopped

type WorkerStopped struct {
	URL       string
	ServiceID string
	Error     error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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