internal

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2019 License: MIT Imports: 33 Imported by: 0

README

Mirr

An IPFS DApp that mirrors the old web, a.k.a, the world wide web. it has a built-in forward proxy and load balancer to distribute the load to multiple peers.

Usage

$ ./mirr -port 18080

Credits

https://github.com/voldyman/GoLoadBalance

https://github.com/kintoandar/fwd

https://github.com/elazarl/goproxy

License

Mirr is released under MIT license

Author: Qiang Li liqiang@gmail.com

Documentation

Overview

https://github.com/kintoandar/fwd

https://github.com/elazarl/goproxy

https://github.com/carlescere/scheduler Package scheduler is a cron replacement based on:

http://adam.herokuapp.com/past/2010/4/13/rethinking_cron/

and

https://github.com/dbader/schedule

Uses include:

 func main() {
   job := func() {
	fmt.Println("Time's up!")
   }
   scheduler.Every(5).Seconds().Run(function)
   scheduler.Every().Day().Run(function)
   scheduler.Every().Sunday().At("08:30").Run(function)
 }

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPath

func AddPath(env string, p []string) string

AddPath adds list of pathes the PATH env per OS convention

func BackoffDuration

func BackoffDuration() func(error)

BackoffDuration is

func CurrentTime

func CurrentTime() int64

CurrentTime is

func DefaultEnviron

func DefaultEnviron(base string) []string

DefaultEnviron returns required env slice for running core services

func Execute

func Execute(base, file string, args ...string) error

Execute sets up env and runs file

func Forward

func Forward(from, to string)

func FreePort

func FreePort() int

FreePort is

func GetIntEnv

func GetIntEnv(env string, i int) int

GetIntEnv returns int env or default

func HTTPProxy

func HTTPProxy(port int, nb *Neighborhood)

HTTPProxy dispatches request based on network addr

func HealthHandlerFunc

func HealthHandlerFunc(proxyURL string) http.HandlerFunc

func IsLocalHost

func IsLocalHost(host string) bool

IsLocalHost checks whether host is explicitly local host taken from goproxy

func LocalProxy

func LocalProxy(port int)

LocalProxy start a local proxy to w3

func Logger

func Logger() *logrus.Entry

Logger exports logger

func MuxHandlerFunc

func MuxHandlerFunc(proxyURL string) http.HandlerFunc

MuxHandlerFunc multiplexes requests

func P2PCloseAll

func P2PCloseAll() error

func P2PListen

func P2PListen(appPort int) error

ipfs p2p listen /x/www/1.0 /ip4/127.0.0.1/tcp/$APP_PORT

func PACHandlerFunc

func PACHandlerFunc(proxyURL string) http.HandlerFunc

PACHandlerFunc handles PAC file request

func ParseInt

func ParseInt(s string, v int) int

ParseInt parses s into int

func PathJoinList

func PathJoinList(p []string) string

PathJoinList is the inverse operation of filepath.SplitList

func PeerTLD

func PeerTLD(domain string) string

PeerTLD splits and returns peer id after strippig off m3

func SetDefaultEnviron

func SetDefaultEnviron(base string)

SetDefaultEnviron sets required env for running core services

func StartGPM

func StartGPM(base string)

StartGPM runs gpm server

func StartProxy

func StartProxy(cfg *Config)

StartProxy starts proxy services

func TLD

func TLD(domain string) string

TLD returns last part of a domain name

func ToPeerAddr

func ToPeerAddr(s string) string

ToPeerAddr returns b32-encoded ID. it converts to b32 if B58-encoded.

func ToPeerID

func ToPeerID(s string) string

ToPeerID returns b58-encoded ID. it converts to b58 if b32-encoded.

func ToTimestamp

func ToTimestamp(d time.Time) int64

func W3Proxy

func W3Proxy(pid string, port int)

W3Proxy start a proxy to W3

Types

type AppDesc

type AppDesc struct {
	Name             string `json:"name"`
	Command          string `json:"command"`
	AutoRestart      bool   `json:"autoRestart"`
	After            string `json:"after"`
	WorkingDirectory string `json:"workDir"`
}

func LoadAppDesc

func LoadAppDesc(name string) (*AppDesc, error)

LoadAppDesc loads app configuration by name from ./, $dhnt_base/etc/ or $HOME/dhnt/etc/

type Backend

type Backend struct {
	Hostname string
	Port     int
	Healthy  bool
}

type Config

type Config struct {
	Port      int
	RouteFile string
}

Config is application settings

type GPM

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

func NewGPM

func NewGPM(base string) *GPM

func (*GPM) Run

func (r *GPM) Run()

Run starts core services

func (*GPM) Start

func (r *GPM) Start()

Start starts core services: p2p, git, and proxy

func (*GPM) Stop

func (r *GPM) Stop()

Stop stops core services

type Health

type Health struct {
	Healthy   bool  `json:"healthy"`
	Timestamp int64 `json:"timestamp"`
}

type Job

type Job struct {
	Quit     chan bool
	SkipWait chan bool

	sync.RWMutex
	// contains filtered or unexported fields
}

Job defines a running job and allows to stop a scheduled job or run it.

func Every

func Every(times ...int) *Job

Every defines when to run a job. For a recurrent jobs (n seconds/minutes/hours) you should specify the unit and then call to the correspondent period method.

func (*Job) At

func (j *Job) At(hourTime string) *Job

At lets you define a specific time when the job would be run. Does not work with recurrent jobs. Time should be defined as a string separated by a colon. Could be used as "08:35:30", "08:35" or "8" for only the hours.

func (*Job) Day

func (j *Job) Day() *Job

Day sets the job to run every day.

func (*Job) Friday

func (j *Job) Friday() *Job

Friday sets the job to run every Friday.

func (*Job) Hours

func (j *Job) Hours() *Job

Hours sets the job to run every n Hours where n was defined in the Every function.

func (*Job) IsRunning

func (j *Job) IsRunning() bool

IsRunning returns if the job is currently running

func (*Job) Minutes

func (j *Job) Minutes() *Job

Minutes sets the job to run every n Minutes where n was defined in the Every function.

func (*Job) Monday

func (j *Job) Monday() *Job

Monday sets the job to run every Monday.

func (*Job) NotImmediately

func (j *Job) NotImmediately() *Job

NotImmediately allows recurrent jobs not to be executed immediatelly after definition. If a job is declared hourly won't start executing until the first hour passed.

func (*Job) Run

func (j *Job) Run(f func()) (*Job, error)

Run sets the job to the schedule and returns the pointer to the job so it may be stopped or executed without waiting or an error.

func (*Job) Saturday

func (j *Job) Saturday() *Job

Saturday sets the job to run every Saturday.

func (*Job) Seconds

func (j *Job) Seconds() *Job

Seconds sets the job to run every n Seconds where n was defined in the Every function.

func (*Job) Sunday

func (j *Job) Sunday() *Job

Sunday sets the job to run every Sunday.

func (*Job) Thursday

func (j *Job) Thursday() *Job

Thursday sets the job to run every Thursday.

func (*Job) Tuesday

func (j *Job) Tuesday() *Job

Tuesday sets the job to run every Tuesday.

func (*Job) Wednesday

func (j *Job) Wednesday() *Job

Wednesday sets the job to run every Wednesday.

type ListFlags

type ListFlags []string

ListFlags is for collecting an array of command line arguments

func (*ListFlags) Set

func (r *ListFlags) Set(value string) error

Set appends the value

func (*ListFlags) String

func (r *ListFlags) String() string

type Neighborhood

type Neighborhood struct {
	Peers  map[string]*Peer
	My     *Node
	Router *RouteRegistry

	sync.Mutex
	// contains filtered or unexported fields
}

Neighborhood is

func NewNeighborhood

func NewNeighborhood(c *Config) *Neighborhood

NewNeighborhood is

func (*Neighborhood) AddPeerProxy

func (r *Neighborhood) AddPeerProxy(id string) string

func (*Neighborhood) GetPeerTarget

func (r *Neighborhood) GetPeerTarget(id string) string

GetPeerTarget returns peer proxy host:port

func (*Neighborhood) GetPeers

func (r *Neighborhood) GetPeers() []string

GetPeers is

func (*Neighborhood) IsReady

func (r *Neighborhood) IsReady() bool

IsReady tests if node is available

type Node

type Node struct {
	ID              string
	PublicKey       string
	Addresses       []string
	AgentVersion    string
	ProtocolVersion string
}

Node is

type Peer

type Peer struct {
	Port    int
	Peer    string
	Latency string
	Muxer   string
	Streams []struct {
		Protocol string
	}

	Rank int // -1, 0, 1 ...
	// contains filtered or unexported fields
}

Peer is

type Peers

type Peers struct {
	Peers []Peer
}

Peers is

type Route

type Route struct {
	Backend []*Backend
	Proxy   bool
	// contains filtered or unexported fields
}

A Route maps a match on a domain name to a backend.

type RouteRegistry

type RouteRegistry struct {
	MyID   string
	MyAddr string
	Routes []*Route
	// contains filtered or unexported fields
}

RouteRegistry stores the routing configuration.

func NewRouteRegistry

func NewRouteRegistry(myid string) *RouteRegistry

NewRouteRegistry instantiates a new route registry

func (*RouteRegistry) Match

func (c *RouteRegistry) Match(hostname string) ([]*Backend, bool)

Match returns the backend for hostname, and whether to use proxy.

func (*RouteRegistry) Read

func (c *RouteRegistry) Read(reader io.Reader) error

Read replaces current config

func (*RouteRegistry) ReadFile

func (c *RouteRegistry) ReadFile(path string) error

ReadFile replaces the current routes with one read from path.

func (*RouteRegistry) ReadString

func (c *RouteRegistry) ReadString(cfg string) error

ReadString replaces the current routes with one read from cfg.

Directories

Path Synopsis
https://github.com/voldyman/GoLoadBalance
https://github.com/voldyman/GoLoadBalance

Jump to

Keyboard shortcuts

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