Skip to content
Snippets Groups Projects
Commit 007d20e5 authored by Hans Moog's avatar Hans Moog
Browse files

Feat: added a plugin for the port checks

parent 2111bb9c
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@ require (
github.com/iotaledger/hive.go v0.0.0-20200217140357-8f1ea1f52085
github.com/iotaledger/iota.go v1.0.0-beta.14
github.com/labstack/echo v3.3.10+incompatible
github.com/labstack/gommon v0.3.0 // indirect
github.com/labstack/gommon v0.3.0
github.com/magiconair/properties v1.8.1
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.11 // indirect
......
......@@ -13,6 +13,7 @@ import (
"github.com/iotaledger/goshimmer/plugins/gracefulshutdown"
"github.com/iotaledger/goshimmer/plugins/logger"
"github.com/iotaledger/goshimmer/plugins/metrics"
"github.com/iotaledger/goshimmer/plugins/portcheck"
"github.com/iotaledger/goshimmer/plugins/remotelog"
"github.com/iotaledger/goshimmer/plugins/tangle"
"github.com/iotaledger/goshimmer/plugins/webapi"
......@@ -37,6 +38,7 @@ func main() {
autopeering.PLUGIN,
tangle.PLUGIN,
gossip.PLUGIN,
portcheck.PLUGIN,
gracefulshutdown.PLUGIN,
analysis.PLUGIN,
......
......@@ -16,9 +16,7 @@ import (
"github.com/iotaledger/hive.go/logger"
"github.com/iotaledger/hive.go/node"
"github.com/iotaledger/goshimmer/packages/netutil"
"github.com/iotaledger/goshimmer/plugins/autopeering/local"
"github.com/iotaledger/goshimmer/plugins/banner"
"github.com/iotaledger/goshimmer/plugins/config"
"github.com/iotaledger/goshimmer/plugins/gossip"
)
......@@ -92,11 +90,6 @@ func start(shutdownSignal <-chan struct{}) {
log.Fatalf("Error resolving %s: %v", local.CFG_BIND, err)
}
// check that discovery is working and the port is open
log.Info("Testing service ...")
checkConnection(localAddr, &lPeer.Peer)
log.Info("Testing service ... done")
conn, err := net.ListenUDP(peeringAddr.Network(), localAddr)
if err != nil {
log.Fatalf("Error listening: %v", err)
......@@ -159,19 +152,3 @@ func parseEntryNodes() (result []*peer.Peer, err error) {
return result, nil
}
func checkConnection(localAddr *net.UDPAddr, self *peer.Peer) {
peering := self.Services().Get(service.PeeringKey)
remoteAddr, err := net.ResolveUDPAddr(peering.Network(), peering.String())
if err != nil {
panic(err)
}
// do not check the address as a NAT may change them for local connections
err = netutil.CheckUDP(localAddr, remoteAddr, false, true)
if err != nil {
log.Errorf("Error testing service: %s", err)
log.Panicf("Please check that %s is publicly reachable at %s/%s",
banner.AppName, peering.String(), peering.Network())
}
}
......@@ -4,9 +4,7 @@ import (
"fmt"
"net"
"strconv"
"sync"
"github.com/iotaledger/hive.go/autopeering/peer"
"github.com/iotaledger/hive.go/autopeering/peer/service"
"github.com/iotaledger/hive.go/logger"
......@@ -14,7 +12,6 @@ import (
gp "github.com/iotaledger/goshimmer/packages/gossip"
"github.com/iotaledger/goshimmer/packages/gossip/server"
"github.com/iotaledger/goshimmer/plugins/autopeering/local"
"github.com/iotaledger/goshimmer/plugins/banner"
"github.com/iotaledger/goshimmer/plugins/config"
"github.com/iotaledger/goshimmer/plugins/tangle"
)
......@@ -22,6 +19,7 @@ import (
var (
log *logger.Logger
mgr *gp.Manager
Srv *server.TCP
)
func configureGossip() {
......@@ -66,15 +64,10 @@ func start(shutdownSignal <-chan struct{}) {
}
defer listener.Close()
srv := server.ServeTCP(lPeer, listener, log)
defer srv.Close()
Srv = server.ServeTCP(lPeer, listener, log)
defer Srv.Close()
//check that the server is working and the port is open
log.Info("Testing service ...")
checkConnection(srv, &lPeer.Peer)
log.Info("Testing service ... done")
mgr.Start(srv)
mgr.Start(Srv)
defer mgr.Close()
log.Infof("%s started: Address=%s/%s", name, gossipAddr.String(), gossipAddr.Network())
......@@ -83,28 +76,6 @@ func start(shutdownSignal <-chan struct{}) {
log.Info("Stopping " + name + " ...")
}
func checkConnection(srv *server.TCP, self *peer.Peer) {
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
conn, err := srv.AcceptPeer(self)
if err != nil {
return
}
_ = conn.Close()
}()
conn, err := srv.DialPeer(self)
if err != nil {
log.Errorf("Error testing: %s", err)
addr := self.Services().Get(service.GossipKey)
log.Panicf("Please check that %s is publicly reachable at %s/%s",
banner.AppName, addr.String(), addr.Network())
}
_ = conn.Close()
wg.Wait()
}
func getTransaction(transactionId transaction.Id) (bytes []byte, err error) {
log.Debugw("get tx from db", "id", transactionId.String())
......
package portcheck
import (
"net"
"sync"
"github.com/iotaledger/goshimmer/packages/gossip/server"
"github.com/iotaledger/goshimmer/packages/netutil"
"github.com/iotaledger/goshimmer/plugins/autopeering/local"
"github.com/iotaledger/goshimmer/plugins/banner"
"github.com/iotaledger/goshimmer/plugins/config"
"github.com/iotaledger/goshimmer/plugins/gossip"
"github.com/iotaledger/hive.go/autopeering/peer"
"github.com/iotaledger/hive.go/autopeering/peer/service"
"github.com/iotaledger/hive.go/logger"
"github.com/iotaledger/hive.go/node"
)
var PLUGIN = node.NewPlugin("Port Check", node.Enabled, run)
var log *logger.Logger
func run(ctx *node.Plugin) {
log = logger.NewLogger("Tangle")
lPeer := local.GetInstance()
// use the port of the peering service
peeringAddr := lPeer.Services().Get(service.PeeringKey)
_, peeringPort, err := net.SplitHostPort(peeringAddr.String())
if err != nil {
panic(err)
}
// resolve the bind address
address := net.JoinHostPort(config.NodeConfig.GetString(local.CFG_BIND), peeringPort)
localAddr, err := net.ResolveUDPAddr(peeringAddr.Network(), address)
if err != nil {
log.Fatalf("Error resolving %s: %v", local.CFG_BIND, err)
}
// check that discovery is working and the port is open
log.Info("Testing service ...")
checkAutopeeringConnection(localAddr, &lPeer.Peer)
log.Info("Testing service ... done")
//check that the server is working and the port is open
log.Info("Testing service ...")
checkGossipConnection(gossip.Srv, &lPeer.Peer)
log.Info("Testing service ... done")
}
func checkAutopeeringConnection(localAddr *net.UDPAddr, self *peer.Peer) {
peering := self.Services().Get(service.PeeringKey)
remoteAddr, err := net.ResolveUDPAddr(peering.Network(), peering.String())
if err != nil {
panic(err)
}
// do not check the address as a NAT may change them for local connections
err = netutil.CheckUDP(localAddr, remoteAddr, false, true)
if err != nil {
log.Errorf("Error testing service: %s", err)
log.Panicf("Please check that %s is publicly reachable at %s/%s",
banner.AppName, peering.String(), peering.Network())
}
}
func checkGossipConnection(srv *server.TCP, self *peer.Peer) {
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
conn, err := srv.AcceptPeer(self)
if err != nil {
return
}
_ = conn.Close()
}()
conn, err := srv.DialPeer(self)
if err != nil {
log.Errorf("Error testing: %s", err)
addr := self.Services().Get(service.GossipKey)
log.Panicf("Please check that %s is publicly reachable at %s/%s",
banner.AppName, addr.String(), addr.Network())
}
_ = conn.Close()
wg.Wait()
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment