Skip to content
Snippets Groups Projects
Commit 6d13ad3a authored by capossele's avatar capossele
Browse files

:construction: WIP

parent 7e81eac9
No related branches found
No related tags found
No related merge requests found
...@@ -81,12 +81,12 @@ func (m *Manager) getNeighbors(ids ...peer.ID) []*neighbor { ...@@ -81,12 +81,12 @@ func (m *Manager) getNeighbors(ids ...peer.ID) []*neighbor {
} }
func (m *Manager) getAllNeighbors() []*neighbor { func (m *Manager) getAllNeighbors() []*neighbor {
m.mu.Lock() m.mu.RLock()
result := make([]*neighbor, 0, len(m.neighbors)) result := make([]*neighbor, 0, len(m.neighbors))
for _, n := range m.neighbors { for _, n := range m.neighbors {
result = append(result, n) result = append(result, n)
} }
m.mu.Unlock() m.mu.RUnlock()
return result return result
} }
......
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
gp "github.com/iotaledger/goshimmer/packages/gossip" gp "github.com/iotaledger/goshimmer/packages/gossip"
pb "github.com/iotaledger/goshimmer/packages/gossip/proto" pb "github.com/iotaledger/goshimmer/packages/gossip/proto"
"github.com/iotaledger/goshimmer/packages/gossip/transport" "github.com/iotaledger/goshimmer/packages/gossip/transport"
"github.com/iotaledger/goshimmer/packages/model/meta_transaction" "github.com/iotaledger/goshimmer/packages/model/value_transaction"
"github.com/iotaledger/goshimmer/plugins/autopeering/local" "github.com/iotaledger/goshimmer/plugins/autopeering/local"
"github.com/iotaledger/goshimmer/plugins/tangle" "github.com/iotaledger/goshimmer/plugins/tangle"
"github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/events"
...@@ -37,14 +37,9 @@ const defaultZLC = `{ ...@@ -37,14 +37,9 @@ const defaultZLC = `{
}` }`
var ( var (
debugLevel = "debug" debugLevel = "debug"
zLogger *zap.SugaredLogger zLogger *zap.SugaredLogger
mgr *gp.Manager mgr *gp.Manager
SendTransaction = mgr.SendTransaction
RequestTransaction = mgr.RequestTransaction
AddInbound = mgr.AddInbound
AddOutbound = mgr.AddOutbound
DropNeighbor = mgr.DropNeighbor
) )
func getTransaction(h []byte) ([]byte, error) { func getTransaction(h []byte) ([]byte, error) {
...@@ -64,6 +59,7 @@ func configureGossip() { ...@@ -64,6 +59,7 @@ func configureGossip() {
} }
mgr = gp.NewManager(trans, zLogger, getTransaction) mgr = gp.NewManager(trans, zLogger, getTransaction)
log.Info("Gossip started @", trans.LocalAddr().String()) log.Info("Gossip started @", trans.LocalAddr().String())
} }
...@@ -78,7 +74,6 @@ func configureEvents() { ...@@ -78,7 +74,6 @@ func configureEvents() {
gossipService := ev.Peer.Services().Get(service.GossipKey) gossipService := ev.Peer.Services().Get(service.GossipKey)
if gossipService != nil { if gossipService != nil {
log.Info("accepted neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String()) log.Info("accepted neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String())
//address, port, _ := net.SplitHostPort(ev.Peer.Services().Get(service.GossipKey).String())
go mgr.AddInbound(ev.Peer) go mgr.AddInbound(ev.Peer)
} }
})) }))
...@@ -87,20 +82,19 @@ func configureEvents() { ...@@ -87,20 +82,19 @@ func configureEvents() {
gossipService := ev.Peer.Services().Get(service.GossipKey) gossipService := ev.Peer.Services().Get(service.GossipKey)
if gossipService != nil { if gossipService != nil {
log.Info("chosen neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String()) log.Info("chosen neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String())
//address, port, _ := net.SplitHostPort(ev.Peer.Services().Get(service.GossipKey).String())
go mgr.AddOutbound(ev.Peer) go mgr.AddOutbound(ev.Peer)
} }
})) }))
tangle.Events.TransactionSolid.Attach(events.NewClosure(func(tx *meta_transaction.MetaTransaction) { tangle.Events.TransactionSolid.Attach(events.NewClosure(func(tx *value_transaction.ValueTransaction) {
log.Info("Tx solidified") log.Info("Tx solidified")
t := &pb.Transaction{ t := &pb.Transaction{
Body: tx.GetBytes(), Body: tx.MetaTransaction.GetBytes(),
} }
b, err := proto.Marshal(t) b, err := proto.Marshal(t)
if err != nil { if err != nil {
return return
} }
go SendTransaction(b) go mgr.SendTransaction(b)
})) }))
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment