Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue#325 #354

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -26,4 +26,5 @@
**/pb/*.pb.go
**/pb/*.pb.gw.go
**/pb/*.swagger.json
database/data
database/data
go-spacemesh.exe
2 changes: 2 additions & 0 deletions p2p/config/config.go
Expand Up @@ -38,6 +38,7 @@ type Config struct {
ResponseTimeout time.Duration `mapstructure:"response-timeout"`
SwarmConfig SwarmConfig `mapstructure:"swarm"`
TimeConfig TimeConfig
BufferSize int
}

// SwarmConfig specifies swarm config params.
Expand Down Expand Up @@ -92,5 +93,6 @@ func DefaultConfig() Config {
ResponseTimeout: duration("15s"),
SwarmConfig: SwarmConfigValues,
TimeConfig: TimeConfigValues,
BufferSize: 512,
}
}
6 changes: 6 additions & 0 deletions p2p/server/msgserver.go
Expand Up @@ -28,6 +28,11 @@ type Item struct {
timestamp time.Time
}

// Config holds configuration params
type Config struct {
BufferSize int
}

type MessageServer struct {
ReqId uint64 //request id
name string //server name
Expand All @@ -44,6 +49,7 @@ type MessageServer struct {
}

func NewMsgServer(network ServerService, name string, requestLifetime time.Duration) *MessageServer {

p := &MessageServer{
name: name,
pendingMap: make(map[uint64]chan interface{}),
Expand Down
3 changes: 2 additions & 1 deletion p2p/service/sim.go
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"github.com/spacemeshos/go-spacemesh/crypto"
"github.com/spacemeshos/go-spacemesh/log"
"github.com/spacemeshos/go-spacemesh/p2p/config"
"github.com/spacemeshos/go-spacemesh/p2p/node"
"io"
"sync"
Expand Down Expand Up @@ -191,7 +192,7 @@ func (sn *Node) SubscribePeerEvents() (chan crypto.PublicKey, chan crypto.Public

// RegisterProtocol creates and returns a channel for a given protocol.
func (sn *Node) RegisterProtocol(protocol string) chan Message {
c := make(chan Message)
c := make(chan Message, config.ConfigValues.BufferSize)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to change RegisterProtocol like we discussed and refactor the places it is used so the tests still pass.
so basically the only thing to do is change RegisterProtocol(protocol string, bufferSize int) chan Message to RegisterProtocol(protocol string, chan Message)
of course that means that you will have to create and pass the chan when calling RegisterProtocol.

sn.sim.mutex.Lock()
sn.sim.protocolHandler[sn.Node.String()][protocol] = c
sn.sim.mutex.Unlock()
Expand Down