Skip to content
Snippets Groups Projects
Commit 821e9fb6 authored by capossele's avatar capossele
Browse files

:construction: WIP

parent 23b1d72a
No related branches found
No related tags found
No related merge requests found
...@@ -3,11 +3,11 @@ package gossip ...@@ -3,11 +3,11 @@ package gossip
import ( import (
"net" "net"
"github.com/capossele/gossip/neighbor"
pb "github.com/capossele/gossip/proto"
"github.com/capossele/gossip/transport"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/iotaledger/autopeering-sim/peer" "github.com/iotaledger/autopeering-sim/peer"
"github.com/iotaledger/goshimmer/packages/gossip/neighbor"
pb "github.com/iotaledger/goshimmer/packages/gossip/proto"
"github.com/iotaledger/goshimmer/packages/gossip/transport"
"github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/events"
"github.com/pkg/errors" "github.com/pkg/errors"
"go.uber.org/zap" "go.uber.org/zap"
......
...@@ -6,11 +6,11 @@ import ( ...@@ -6,11 +6,11 @@ import (
"testing" "testing"
"time" "time"
pb "github.com/capossele/gossip/proto"
"github.com/capossele/gossip/transport"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/iotaledger/autopeering-sim/peer" "github.com/iotaledger/autopeering-sim/peer"
"github.com/iotaledger/autopeering-sim/peer/service" "github.com/iotaledger/autopeering-sim/peer/service"
pb "github.com/iotaledger/goshimmer/packages/gossip/proto"
"github.com/iotaledger/goshimmer/packages/gossip/transport"
"github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/events"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
......
...@@ -3,8 +3,8 @@ package neighbor ...@@ -3,8 +3,8 @@ package neighbor
import ( import (
"sync" "sync"
"github.com/capossele/gossip/transport"
"github.com/iotaledger/autopeering-sim/peer" "github.com/iotaledger/autopeering-sim/peer"
"github.com/iotaledger/goshimmer/packages/gossip/transport"
) )
// Neighbor defines a neighbor // Neighbor defines a neighbor
......
syntax = "proto3"; syntax = "proto3";
option go_package = "github.com/capossele/gossip/proto"; option go_package = "github.com/iotaledger/goshimmer/packages/gossip/proto";
package proto; package proto;
......
...@@ -4,9 +4,9 @@ import ( ...@@ -4,9 +4,9 @@ import (
"bytes" "bytes"
"time" "time"
pb "github.com/capossele/gossip/transport/proto"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/iotaledger/autopeering-sim/server" "github.com/iotaledger/autopeering-sim/server"
pb "github.com/iotaledger/goshimmer/packages/gossip/transport/proto"
) )
const ( const (
......
syntax = "proto3"; syntax = "proto3";
option go_package = "github.com/capossele/gossip/transport/proto"; option go_package = "github.com/iotaledger/goshimmer/packages/gossip/transport/proto";
package proto; package proto;
......
...@@ -4,8 +4,9 @@ import ( ...@@ -4,8 +4,9 @@ import (
"sync" "sync"
"time" "time"
"github.com/iotaledger/goshimmer/plugins/gossip" "github.com/golang/protobuf/proto"
"github.com/iotaledger/goshimmer/packages/gossip"
pb "github.com/iotaledger/goshimmer/packages/gossip/proto"
"github.com/iotaledger/goshimmer/packages/model/value_transaction" "github.com/iotaledger/goshimmer/packages/model/value_transaction"
"github.com/iotaledger/goshimmer/plugins/tipselection" "github.com/iotaledger/goshimmer/plugins/tipselection"
"github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/daemon"
...@@ -50,7 +51,9 @@ func Start(tps uint) { ...@@ -50,7 +51,9 @@ func Start(tps uint) {
tx.SetBranchTransactionHash(tipselection.GetRandomTip()) tx.SetBranchTransactionHash(tipselection.GetRandomTip())
tx.SetTrunkTransactionHash(tipselection.GetRandomTip()) tx.SetTrunkTransactionHash(tipselection.GetRandomTip())
gossip.Events.ReceiveTransaction.Trigger(tx.MetaTransaction) mtx := &pb.Transaction{Body: tx.MetaTransaction.GetBytes()}
b, _ := proto.Marshal(mtx)
gossip.Event.NewTransaction.Trigger(b)
if sentCounter >= tps { if sentCounter >= tps {
duration := time.Since(start) duration := time.Since(start)
......
package autopeering package autopeering
import ( import (
"net"
"github.com/iotaledger/autopeering-sim/discover" "github.com/iotaledger/autopeering-sim/discover"
"github.com/iotaledger/autopeering-sim/peer/service"
"github.com/iotaledger/autopeering-sim/selection"
"github.com/iotaledger/goshimmer/packages/gossip" "github.com/iotaledger/goshimmer/packages/gossip"
"github.com/iotaledger/goshimmer/packages/gossip/neighbor"
"github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/daemon"
"github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/events"
"github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/logger"
...@@ -29,37 +26,12 @@ func run(plugin *node.Plugin) { ...@@ -29,37 +26,12 @@ func run(plugin *node.Plugin) {
} }
func configureLogging(plugin *node.Plugin) { func configureLogging(plugin *node.Plugin) {
gossip.Event.DropNeighbor.Attach(events.NewClosure(func(peer *gossip.Neighbor) { gossip.Event.DropNeighbor.Attach(events.NewClosure(func(peer *neighbor.Neighbor) {
if Selection != nil { if Selection != nil {
Selection.DropPeer(peer.Peer) Selection.DropPeer(peer.Peer)
} }
})) }))
selection.Events.Dropped.Attach(events.NewClosure(func(ev *selection.DroppedEvent) {
log.Info("neighbor removed: " + ev.DroppedID.String())
gossip.RemoveNeighbor(ev.DroppedID.String())
}))
selection.Events.IncomingPeering.Attach(events.NewClosure(func(ev *selection.PeeringEvent) {
log.Info("accepted neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String())
log.Info("services: " + ev.Peer.Services().CreateRecord().String())
gossipService := ev.Peer.Services().Get(service.GossipKey)
if gossipService != nil {
address, port, _ := net.SplitHostPort(ev.Peer.Services().Get(service.GossipKey).String())
gossip.AddNeighbor(gossip.NewNeighbor(ev.Peer, address, port))
}
}))
selection.Events.OutgoingPeering.Attach(events.NewClosure(func(ev *selection.PeeringEvent) {
log.Info("chosen neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String())
log.Info("services: " + ev.Peer.Services().CreateRecord().String())
gossipService := ev.Peer.Services().Get(service.GossipKey)
if gossipService != nil {
address, port, _ := net.SplitHostPort(ev.Peer.Services().Get(service.GossipKey).String())
gossip.AddNeighbor(gossip.NewNeighbor(ev.Peer, address, port))
}
}))
discover.Events.PeerDiscovered.Attach(events.NewClosure(func(ev *discover.DiscoveredEvent) { discover.Events.PeerDiscovered.Attach(events.NewClosure(func(ev *discover.DiscoveredEvent) {
log.Info("new peer discovered: " + ev.Peer.Address() + " / " + ev.Peer.ID().String()) log.Info("new peer discovered: " + ev.Peer.Address() + " / " + ev.Peer.ID().String())
})) }))
......
package gossip package gossip
import ( import (
"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/meta_transaction"
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/plugins/autopeering/local" "github.com/iotaledger/goshimmer/plugins/autopeering/local"
"github.com/iotaledger/autopeering-sim/peer/service"
"github.com/iotaledger/autopeering-sim/selection" "github.com/iotaledger/autopeering-sim/selection"
"github.com/iotaledger/goshimmer/plugins/tangle" "github.com/iotaledger/goshimmer/plugins/tangle"
"go.uber.org/zap" "go.uber.org/zap"
...@@ -58,13 +60,21 @@ func configureEvents() { ...@@ -58,13 +60,21 @@ func configureEvents() {
})) }))
selection.Events.IncomingPeering.Attach(events.NewClosure(func(ev *selection.PeeringEvent) { selection.Events.IncomingPeering.Attach(events.NewClosure(func(ev *selection.PeeringEvent) {
log.Debug("accepted neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String()) gossipService := ev.Peer.Services().Get(service.GossipKey)
AddInbound(ev.Peer) if gossipService != nil {
log.Debug("accepted neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String())
//address, port, _ := net.SplitHostPort(ev.Peer.Services().Get(service.GossipKey).String())
AddInbound(ev.Peer)
}
})) }))
selection.Events.OutgoingPeering.Attach(events.NewClosure(func(ev *selection.PeeringEvent) { selection.Events.OutgoingPeering.Attach(events.NewClosure(func(ev *selection.PeeringEvent) {
log.Debug("chosen neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String()) gossipService := ev.Peer.Services().Get(service.GossipKey)
AddOutbound(ev.Peer) if gossipService != nil {
log.Debug("chosen neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String())
//address, port, _ := net.SplitHostPort(ev.Peer.Services().Get(service.GossipKey).String())
AddOutbound(ev.Peer)
}
})) }))
// mgr.Events.NewTransaction.Attach(events.NewClosure(func(ev *gp.NewTransactionEvent) { // mgr.Events.NewTransaction.Attach(events.NewClosure(func(ev *gp.NewTransactionEvent) {
......
...@@ -3,9 +3,8 @@ package metrics ...@@ -3,9 +3,8 @@ package metrics
import ( import (
"time" "time"
"github.com/iotaledger/goshimmer/packages/model/meta_transaction" "github.com/iotaledger/goshimmer/packages/gossip"
"github.com/iotaledger/goshimmer/packages/timeutil" "github.com/iotaledger/goshimmer/packages/timeutil"
"github.com/iotaledger/goshimmer/plugins/gossip"
"github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/daemon"
"github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/events"
"github.com/iotaledger/hive.go/node" "github.com/iotaledger/hive.go/node"
...@@ -15,7 +14,7 @@ var PLUGIN = node.NewPlugin("Metrics", node.Enabled, configure, run) ...@@ -15,7 +14,7 @@ var PLUGIN = node.NewPlugin("Metrics", node.Enabled, configure, run)
func configure(plugin *node.Plugin) { func configure(plugin *node.Plugin) {
// increase received TPS counter whenever we receive a new transaction // increase received TPS counter whenever we receive a new transaction
gossip.Events.ReceiveTransaction.Attach(events.NewClosure(func(_ *meta_transaction.MetaTransaction) { increaseReceivedTPSCounter() })) gossip.Event.NewTransaction.Attach(events.NewClosure(func(_ *gossip.NewTransactionEvent) { increaseReceivedTPSCounter() }))
} }
func run(plugin *node.Plugin) { func run(plugin *node.Plugin) {
......
...@@ -5,9 +5,8 @@ import ( ...@@ -5,9 +5,8 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/iotaledger/goshimmer/packages/model/meta_transaction" "github.com/iotaledger/goshimmer/packages/gossip"
"github.com/iotaledger/goshimmer/packages/model/value_transaction" "github.com/iotaledger/goshimmer/packages/model/value_transaction"
"github.com/iotaledger/goshimmer/plugins/gossip"
"github.com/iotaledger/goshimmer/plugins/statusscreen" "github.com/iotaledger/goshimmer/plugins/statusscreen"
"github.com/iotaledger/goshimmer/plugins/tangle" "github.com/iotaledger/goshimmer/plugins/tangle"
"github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/daemon"
...@@ -24,7 +23,7 @@ var receivedTps uint64 ...@@ -24,7 +23,7 @@ var receivedTps uint64
var solidTps uint64 var solidTps uint64
var PLUGIN = node.NewPlugin("Statusscreen TPS", node.Enabled, func(plugin *node.Plugin) { var PLUGIN = node.NewPlugin("Statusscreen TPS", node.Enabled, func(plugin *node.Plugin) {
gossip.Events.ReceiveTransaction.Attach(events.NewClosure(func(_ *meta_transaction.MetaTransaction) { gossip.Event.NewTransaction.Attach(events.NewClosure(func(_ *gossip.NewTransactionEvent) {
atomic.AddUint64(&receivedTpsCounter, 1) atomic.AddUint64(&receivedTpsCounter, 1)
})) }))
......
...@@ -4,12 +4,12 @@ import ( ...@@ -4,12 +4,12 @@ import (
"runtime" "runtime"
"github.com/iotaledger/goshimmer/packages/errors" "github.com/iotaledger/goshimmer/packages/errors"
"github.com/iotaledger/goshimmer/packages/gossip"
"github.com/iotaledger/goshimmer/packages/model/approvers" "github.com/iotaledger/goshimmer/packages/model/approvers"
"github.com/iotaledger/goshimmer/packages/model/meta_transaction" "github.com/iotaledger/goshimmer/packages/model/meta_transaction"
"github.com/iotaledger/goshimmer/packages/model/transactionmetadata" "github.com/iotaledger/goshimmer/packages/model/transactionmetadata"
"github.com/iotaledger/goshimmer/packages/model/value_transaction" "github.com/iotaledger/goshimmer/packages/model/value_transaction"
"github.com/iotaledger/goshimmer/packages/workerpool" "github.com/iotaledger/goshimmer/packages/workerpool"
"github.com/iotaledger/goshimmer/plugins/gossip"
"github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/daemon"
"github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/events"
"github.com/iotaledger/hive.go/node" "github.com/iotaledger/hive.go/node"
...@@ -27,8 +27,10 @@ func configureSolidifier(plugin *node.Plugin) { ...@@ -27,8 +27,10 @@ func configureSolidifier(plugin *node.Plugin) {
task.Return(nil) task.Return(nil)
}, workerpool.WorkerCount(WORKER_COUNT), workerpool.QueueSize(10000)) }, workerpool.WorkerCount(WORKER_COUNT), workerpool.QueueSize(10000))
gossip.Events.ReceiveTransaction.Attach(events.NewClosure(func(rawTransaction *meta_transaction.MetaTransaction) { gossip.Event.NewTransaction.Attach(events.NewClosure(func(ev *gossip.NewTransactionEvent) {
workerPool.Submit(rawTransaction) tx := ev.Body
metaTx := meta_transaction.FromBytes(tx)
workerPool.Submit(metaTx)
})) }))
daemon.Events.Shutdown.Attach(events.NewClosure(func() { daemon.Events.Shutdown.Attach(events.NewClosure(func() {
......
package tangle package tangle
import ( import (
"github.com/iotaledger/hive.go/parameter"
"os" "os"
"sync" "sync"
"testing" "testing"
"github.com/golang/protobuf/proto"
"github.com/iotaledger/hive.go/parameter"
"github.com/iotaledger/goshimmer/packages/gossip"
pb "github.com/iotaledger/goshimmer/packages/gossip/proto"
"github.com/iotaledger/goshimmer/packages/model/value_transaction" "github.com/iotaledger/goshimmer/packages/model/value_transaction"
"github.com/iotaledger/goshimmer/plugins/gossip"
"github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/events"
"github.com/iotaledger/hive.go/node" "github.com/iotaledger/hive.go/node"
"github.com/iotaledger/iota.go/trinary" "github.com/iotaledger/iota.go/trinary"
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
parameter.FetchConfig() parameter.FetchConfig(false)
os.Exit(m.Run()) os.Exit(m.Run())
} }
...@@ -43,10 +46,21 @@ func TestSolidifier(t *testing.T) { ...@@ -43,10 +46,21 @@ func TestSolidifier(t *testing.T) {
// issue transactions // issue transactions
wg.Add(4) wg.Add(4)
gossip.Events.ReceiveTransaction.Trigger(transaction1.MetaTransaction) tx := &pb.Transaction{Body: transaction1.MetaTransaction.GetBytes()}
gossip.Events.ReceiveTransaction.Trigger(transaction2.MetaTransaction) b, _ := proto.Marshal(tx)
gossip.Events.ReceiveTransaction.Trigger(transaction3.MetaTransaction) gossip.Event.NewTransaction.Trigger(b)
gossip.Events.ReceiveTransaction.Trigger(transaction4.MetaTransaction)
tx = &pb.Transaction{Body: transaction2.MetaTransaction.GetBytes()}
b, _ = proto.Marshal(tx)
gossip.Event.NewTransaction.Trigger(b)
tx = &pb.Transaction{Body: transaction3.MetaTransaction.GetBytes()}
b, _ = proto.Marshal(tx)
gossip.Event.NewTransaction.Trigger(b)
tx = &pb.Transaction{Body: transaction4.MetaTransaction.GetBytes()}
b, _ = proto.Marshal(tx)
gossip.Event.NewTransaction.Trigger(b)
// wait until all are solid // wait until all are solid
wg.Wait() wg.Wait()
......
...@@ -6,9 +6,8 @@ import ( ...@@ -6,9 +6,8 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/iotaledger/goshimmer/packages/model/meta_transaction" "github.com/iotaledger/goshimmer/packages/gossip"
"github.com/iotaledger/goshimmer/packages/model/value_transaction" "github.com/iotaledger/goshimmer/packages/model/value_transaction"
"github.com/iotaledger/goshimmer/plugins/gossip"
"github.com/iotaledger/goshimmer/plugins/tangle" "github.com/iotaledger/goshimmer/plugins/tangle"
"github.com/iotaledger/goshimmer/plugins/webapi" "github.com/iotaledger/goshimmer/plugins/webapi"
"github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/daemon"
...@@ -35,7 +34,7 @@ func configure(plugin *node.Plugin) { ...@@ -35,7 +34,7 @@ func configure(plugin *node.Plugin) {
return c.JSON(http.StatusOK, tpsQueue) return c.JSON(http.StatusOK, tpsQueue)
}) })
gossip.Events.ReceiveTransaction.Attach(events.NewClosure(func(_ *meta_transaction.MetaTransaction) { gossip.Event.NewTransaction.Attach(events.NewClosure(func(_ *gossip.NewTransactionEvent) {
atomic.AddUint64(&receivedTpsCounter, 1) atomic.AddUint64(&receivedTpsCounter, 1)
})) }))
tangle.Events.TransactionSolid.Attach(events.NewClosure(func(_ *value_transaction.ValueTransaction) { tangle.Events.TransactionSolid.Attach(events.NewClosure(func(_ *value_transaction.ValueTransaction) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment