connect_controller

package
v1.14.4 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: LGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

* Copyright (C) 2018 The ontology Authors * This file is part of The ontology library. * * The ontology is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The ontology is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with The ontology. If not, see <http://www.gnu.org/licenses/>.

* Copyright (C) 2018 The ontology Authors * This file is part of The ontology library. * * The ontology is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The ontology is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with The ontology. If not, see <http://www.gnu.org/licenses/>.

* Copyright (C) 2018 The ontology Authors * This file is part of The ontology library. * * The ontology is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The ontology is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with The ontology. If not, see <http://www.gnu.org/licenses/>.

* Copyright (C) 2018 The ontology Authors * This file is part of The ontology library. * * The ontology is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The ontology is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with The ontology. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const INBOUND_INDEX = 0
View Source
const OUTBOUND_INDEX = 1

Variables

View Source
var ErrHandshakeSelf = errors.New("the node handshake with itself")

Functions

func NewListener

func NewListener(port uint16, config *config.P2PNodeConfig) (net.Listener, error)

Types

type Conn

type Conn struct {
	net.Conn
	// contains filtered or unexported fields
}

Conn is a net.Conn wrapper to do some clean up when Close.

func (*Conn) Close

func (self *Conn) Close() error

Close overwrite net.Conn warning: this method will try to lock the controller, be carefull to avoid deadlock

type ConnCtrlOption

type ConnCtrlOption struct {
	MaxConnOutBound     uint
	MaxConnInBound      uint
	MaxConnInBoundPerIP uint
	ReservedPeers       p2p.AddressFilter // enabled if not empty
	// contains filtered or unexported fields
}

func ConnCtrlOptionFromConfig

func ConnCtrlOptionFromConfig(config *config.P2PNodeConfig, reserveFilter p2p.AddressFilter) (option ConnCtrlOption, err error)

func NewConnCtrlOption

func NewConnCtrlOption() ConnCtrlOption

func (ConnCtrlOption) MaxInBound

func (self ConnCtrlOption) MaxInBound(n uint) ConnCtrlOption

func (ConnCtrlOption) MaxInBoundPerIp

func (self ConnCtrlOption) MaxInBoundPerIp(n uint) ConnCtrlOption

func (ConnCtrlOption) MaxOutBound

func (self ConnCtrlOption) MaxOutBound(n uint) ConnCtrlOption

func (ConnCtrlOption) ReservedOnly

func (self ConnCtrlOption) ReservedOnly(peers []string) ConnCtrlOption

func (ConnCtrlOption) WithDialer

func (self ConnCtrlOption) WithDialer(dialer Dialer) ConnCtrlOption

type ConnectController

type ConnectController struct {
	ConnCtrlOption
	// contains filtered or unexported fields
}

func NewConnectController

func NewConnectController(peerInfo *peer.PeerInfo, keyid *common.PeerKeyId,
	option ConnCtrlOption, logger common.Logger) *ConnectController

func (*ConnectController) AcceptConnect

func (self *ConnectController) AcceptConnect(conn net.Conn) (*peer.PeerInfo, net.Conn, error)

func (*ConnectController) Connect

func (self *ConnectController) Connect(addr string) (*peer.PeerInfo, net.Conn, error)

Connect used to connect net address under sync or cons mode need call Peer.Close to clean up resource.

func (*ConnectController) InboundsCount

func (self *ConnectController) InboundsCount() uint

func (*ConnectController) OutboundsCount

func (self *ConnectController) OutboundsCount() uint

func (*ConnectController) OwnAddress

func (self *ConnectController) OwnAddress() string

func (*ConnectController) SetOwnAddress added in v1.11.0

func (self *ConnectController) SetOwnAddress(listenAddr string)

type Dialer

type Dialer interface {
	Dial(nodeAddr string) (net.Conn, error)
}

func NewDialer

func NewDialer(config *config.P2PNodeConfig) (Dialer, error)

type StaticReserveFilter added in v1.11.0

type StaticReserveFilter struct {
	//format: host or ip
	ReservedPeers []string
}

func NewStaticReserveFilter added in v1.11.0

func NewStaticReserveFilter(peers []string) *StaticReserveFilter

func (*StaticReserveFilter) Contains added in v1.11.0

func (self *StaticReserveFilter) Contains(remoteIPPort string) bool

remoteAddr format 192.168.1.1:61234 if reserved peers is empty, we should handle this case in subnet now since for gov node, reserve_result = in_subnet_set || in_static_set for normal node, reserve_result = in_static_set || static_set_is_empty because the information of whether self node is gov or not is in subnet module

Jump to

Keyboard shortcuts

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