github.com/impedro29/bor@v0.1.4/p2p/discover/common.go (about)

     1  // Copyright 2019 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package discover
    18  
    19  import (
    20  	"crypto/ecdsa"
    21  	"net"
    22  
    23  	"github.com/maticnetwork/bor/log"
    24  	"github.com/maticnetwork/bor/p2p/enode"
    25  	"github.com/maticnetwork/bor/p2p/netutil"
    26  )
    27  
    28  type UDPConn interface {
    29  	ReadFromUDP(b []byte) (n int, addr *net.UDPAddr, err error)
    30  	WriteToUDP(b []byte, addr *net.UDPAddr) (n int, err error)
    31  	Close() error
    32  	LocalAddr() net.Addr
    33  }
    34  
    35  // Config holds Table-related settings.
    36  type Config struct {
    37  	// These settings are required and configure the UDP listener:
    38  	PrivateKey *ecdsa.PrivateKey
    39  
    40  	// These settings are optional:
    41  	NetRestrict *netutil.Netlist  // network whitelist
    42  	Bootnodes   []*enode.Node     // list of bootstrap nodes
    43  	Unhandled   chan<- ReadPacket // unhandled packets are sent on this channel
    44  	Log         log.Logger        // if set, log messages go here
    45  }
    46  
    47  // ListenUDP starts listening for discovery packets on the given UDP socket.
    48  func ListenUDP(c UDPConn, ln *enode.LocalNode, cfg Config) (*UDPv4, error) {
    49  	return ListenV4(c, ln, cfg)
    50  }
    51  
    52  // ReadPacket is a packet that couldn't be handled. Those packets are sent to the unhandled
    53  // channel if configured.
    54  type ReadPacket struct {
    55  	Data []byte
    56  	Addr *net.UDPAddr
    57  }