mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 19:50:36 +00:00
Test that torrent port is open for TCP and UDP (#4062)
This commit is contained in:
parent
c9a1c93b44
commit
beafe7db65
@ -3,6 +3,7 @@ package downloader
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"runtime"
|
||||
"sync"
|
||||
"time"
|
||||
@ -27,7 +28,33 @@ type Protocols struct {
|
||||
snapshotDir *dir.Rw
|
||||
}
|
||||
|
||||
func portMustBeTCPAndUDPOpen(port int) error {
|
||||
tcpAddr := &net.TCPAddr{
|
||||
Port: port,
|
||||
IP: net.ParseIP("127.0.0.1"),
|
||||
}
|
||||
ln, err := net.ListenTCP("tcp", tcpAddr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("please open port %d for TCP and UDP. %w", port, err)
|
||||
}
|
||||
_ = ln.Close()
|
||||
udpAddr := &net.UDPAddr{
|
||||
Port: port,
|
||||
IP: net.ParseIP("127.0.0.1"),
|
||||
}
|
||||
ser, err := net.ListenUDP("udp", udpAddr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("please open port %d for UDP. %w", port, err)
|
||||
}
|
||||
_ = ser.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
func New(cfg *torrentcfg.Cfg, snapshotDir *dir.Rw) (*Protocols, error) {
|
||||
if err := portMustBeTCPAndUDPOpen(cfg.ListenPort); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
peerID, err := readPeerID(cfg.DB)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get peer id: %w", err)
|
||||
|
Loading…
Reference in New Issue
Block a user