Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
goshimmer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iota-imt
goshimmer
Commits
7b839fb2
Unverified
Commit
7b839fb2
authored
5 years ago
by
Jonas Theis
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Clean up PortCheck plugin and make it standalone #259 (#271)
Co-authored-by:
Hans Moog
<
hm@mkjc.net
>
parent
6b7393c4
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
main.go
+2
-2
2 additions, 2 deletions
main.go
plugins/gossip/gossip.go
+4
-4
4 additions, 4 deletions
plugins/gossip/gossip.go
plugins/portcheck/plugin.go
+64
-30
64 additions, 30 deletions
plugins/portcheck/plugin.go
with
70 additions
and
36 deletions
main.go
+
2
−
2
View file @
7b839fb2
...
...
@@ -38,12 +38,12 @@ func main() {
logger
.
PLUGIN
,
cli
.
PLUGIN
,
remotelog
.
PLUGIN
,
gracefulshutdown
.
PLUGIN
,
portcheck
.
PLUGIN
,
autopeering
.
PLUGIN
,
tangle
.
PLUGIN
,
gossip
.
PLUGIN
,
portcheck
.
PLUGIN
,
gracefulshutdown
.
PLUGIN
,
analysis
.
PLUGIN
,
metrics
.
PLUGIN
,
...
...
This diff is collapsed.
Click to expand it.
plugins/gossip/gossip.go
+
4
−
4
View file @
7b839fb2
...
...
@@ -19,7 +19,7 @@ import (
var
(
log
*
logger
.
Logger
mgr
*
gp
.
Manager
S
rv
*
server
.
TCP
s
rv
*
server
.
TCP
)
func
configureGossip
()
{
...
...
@@ -64,10 +64,10 @@ func start(shutdownSignal <-chan struct{}) {
}
defer
listener
.
Close
()
S
rv
=
server
.
ServeTCP
(
lPeer
,
listener
,
log
)
defer
S
rv
.
Close
()
s
rv
=
server
.
ServeTCP
(
lPeer
,
listener
,
log
)
defer
s
rv
.
Close
()
mgr
.
Start
(
S
rv
)
mgr
.
Start
(
s
rv
)
defer
mgr
.
Close
()
log
.
Infof
(
"%s started: Address=%s/%s"
,
name
,
gossipAddr
.
String
(),
gossipAddr
.
Network
())
...
...
This diff is collapsed.
Click to expand it.
plugins/portcheck/plugin.go
+
64
−
30
View file @
7b839fb2
...
...
@@ -6,84 +6,118 @@ import (
"github.com/iotaledger/goshimmer/packages/gossip/server"
"github.com/iotaledger/goshimmer/packages/netutil"
"github.com/iotaledger/goshimmer/plugins/autopeering"
"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
)
const
(
PLUGIN_NAME
=
"PortCheck"
)
var
(
PLUGIN
=
node
.
NewPlugin
(
PLUGIN_NAME
,
node
.
Enabled
,
configure
,
run
)
log
*
logger
.
Logger
)
var
log
*
logger
.
Logger
func
configure
(
plugin
*
node
.
Plugin
)
{
log
=
logger
.
NewLogger
(
PLUGIN_NAME
)
}
func
run
(
ctx
*
node
.
Plugin
)
{
log
=
logger
.
NewLogger
(
"Tangle"
)
if
!
node
.
IsSkipped
(
autopeering
.
PLUGIN
)
{
log
.
Info
(
"Testing autopeering service ..."
)
checkAutopeeringConnection
()
log
.
Info
(
"Testing autopeering service ... done"
)
}
lPeer
:=
local
.
GetInstance
()
if
!
node
.
IsSkipped
(
gossip
.
PLUGIN
)
{
log
.
Info
(
"Testing gossip service ..."
)
checkGossipConnection
()
log
.
Info
(
"Testing gossip service ... done"
)
}
}
// check that discovery is working and the port is open
func
checkAutopeeringConnection
()
{
peering
:=
local
.
GetInstance
()
.
Services
()
.
Get
(
service
.
PeeringKey
)
// use the port of the peering service
peeringAddr
:=
lPeer
.
Services
()
.
Get
(
service
.
PeeringKey
)
_
,
peeringPort
,
err
:=
net
.
SplitHostPort
(
peeringAddr
.
String
())
_
,
peeringPort
,
err
:=
net
.
SplitHostPort
(
peering
.
String
())
if
err
!=
nil
{
panic
(
err
)
}
// resolve the bind address
address
:=
net
.
JoinHostPort
(
config
.
Node
.
GetString
(
local
.
CFG_BIND
),
peeringPort
)
localAddr
,
err
:=
net
.
ResolveUDPAddr
(
peering
Addr
.
Network
(),
address
)
localAddr
,
err
:=
net
.
ResolveUDPAddr
(
peering
.
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
,
tru
e
)
// do not check address
and port
as a NAT may change them for local connections
err
=
netutil
.
CheckUDP
(
localAddr
,
remoteAddr
,
false
,
fals
e
)
if
err
!=
nil
{
log
.
Errorf
(
"Error testing service: %s"
,
err
)
log
.
Errorf
(
"Error testing
autopeering
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
)
{
// check that the gossip server is working and the port is open
func
checkGossipConnection
()
{
// listen on TCP gossip port
lPeer
:=
local
.
GetInstance
()
// use the port of the gossip service
gossipAddr
:=
lPeer
.
Services
()
.
Get
(
service
.
GossipKey
)
_
,
gossipPort
,
err
:=
net
.
SplitHostPort
(
gossipAddr
.
String
())
if
err
!=
nil
{
panic
(
err
)
}
// resolve the bind address
address
:=
net
.
JoinHostPort
(
config
.
Node
.
GetString
(
local
.
CFG_BIND
),
gossipPort
)
localAddr
,
err
:=
net
.
ResolveTCPAddr
(
gossipAddr
.
Network
(),
address
)
if
err
!=
nil
{
log
.
Fatalf
(
"Error resolving %s: %v"
,
local
.
CFG_BIND
,
err
)
}
listener
,
err
:=
net
.
ListenTCP
(
gossipAddr
.
Network
(),
localAddr
)
if
err
!=
nil
{
log
.
Fatalf
(
"Error listening: %v"
,
err
)
}
defer
listener
.
Close
()
srv
:=
server
.
ServeTCP
(
lPeer
,
listener
,
log
)
defer
srv
.
Close
()
// do the actual check
var
wg
sync
.
WaitGroup
wg
.
Add
(
1
)
go
func
()
{
defer
wg
.
Done
()
conn
,
e
rr
:=
srv
.
AcceptPeer
(
self
)
if
e
rr
!=
nil
{
conn
,
acceptE
rr
:=
srv
.
AcceptPeer
(
&
lPeer
.
Peer
)
if
acceptE
rr
!=
nil
{
return
}
_
=
conn
.
Close
()
}()
conn
,
err
:=
srv
.
DialPeer
(
self
)
conn
,
err
:=
srv
.
DialPeer
(
&
lPeer
.
Peer
)
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
,
a
ddr
.
String
(),
a
ddr
.
Network
())
banner
.
AppName
,
gossipA
ddr
.
String
(),
gossipA
ddr
.
Network
())
}
_
=
conn
.
Close
()
wg
.
Wait
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment