diff --git a/cmd/cmd.go b/cmd/cmd.go index 1a2392364..b59cc6bf5 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -393,17 +393,17 @@ func StartNode(workingDir string, passwordFetcher func(*wallet.Wallet) (string, return nil, nil, err } - nodeInstance, err := node.NewNode(gen, conf, valKeys, rewardAddrs) + nd, err := node.NewNode(gen, conf, valKeys, rewardAddrs) if err != nil { return nil, nil, err } - err = nodeInstance.Start() + err = nd.Start() if err != nil { return nil, nil, err } - return nodeInstance, walletInstance, nil + return nd, walletInstance, nil } // makeLocalGenesis makes genesis file for the local network. diff --git a/cmd/gtk/main.go b/cmd/gtk/main.go index 05b0891f0..451466828 100644 --- a/cmd/gtk/main.go +++ b/cmd/gtk/main.go @@ -84,7 +84,7 @@ func main() { log.Println("application startup") }) - n, wlt, err := newNode(workingDir) + nd, wlt, err := newNode(workingDir) fatalErrorCheck(err) // Connect function to application activate event @@ -111,7 +111,7 @@ func main() { // Running the run-up logic in a separate goroutine glib.TimeoutAdd(uint(100), func() bool { - run(n, wlt, app) + run(nd, wlt, app) splashDlg.Destroy() // Ensures the function is not called again @@ -122,14 +122,14 @@ func main() { // Connect function to application shutdown event, this is not required. app.Connect("shutdown", func() { log.Println("Application shutdown") - n.Stop() + nd.Stop() _ = fileLock.Unlock() }) cmd.TrapSignal(func() { cmd.PrintInfoMsgf("Exiting...") - n.Stop() + nd.Stop() _ = fileLock.Unlock() }) diff --git a/config/example_config.toml b/config/example_config.toml index f34fbaef3..f5e313de7 100644 --- a/config/example_config.toml +++ b/config/example_config.toml @@ -92,10 +92,6 @@ # Default is `10s`. session_timeout = "10s" - # `node_network` indicates whether the node is capable of serving the complete blockchain. - # Default is `true`. - node_network = true - # `sync.firewall` contains configuration options for the sync firewall. [sync.firewall] # `banned_nets` contains the list of IPs and subnets that should be banned. diff --git a/node/node.go b/node/node.go index 3ff0f80b0..b4858d1d3 100644 --- a/node/node.go +++ b/node/node.go @@ -13,6 +13,7 @@ import ( "github.com/pactus-project/pactus/store" "github.com/pactus-project/pactus/sync" "github.com/pactus-project/pactus/sync/bundle/message" + "github.com/pactus-project/pactus/sync/peerset/peer/service" "github.com/pactus-project/pactus/txpool" "github.com/pactus-project/pactus/util" "github.com/pactus-project/pactus/util/logger" @@ -79,6 +80,9 @@ func NewNode(genDoc *genesis.Genesis, conf *config.Config, consMgr := consensus.NewManager(conf.Consensus, st, valKeys, rewardAddrs, messageCh) walletMgr := wallet.NewWalletManager(conf.WalletManager) + if !str.IsPruned() { + conf.Sync.Services.Append(service.FullNode) + } syn, err := sync.NewSynchronizer(conf.Sync, valKeys, st, consMgr, net, messageCh) if err != nil { return nil, err diff --git a/node/node_test.go b/node/node_test.go index 566f874e3..46785f3bc 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -40,12 +40,14 @@ func TestRunningNode(t *testing.T) { valKeys := []*bls.ValidatorKey{ts.RandValKey(), ts.RandValKey()} rewardAddrs := []crypto.Address{ts.RandAccAddress(), ts.RandAccAddress()} - n, err := NewNode(gen, conf, valKeys, rewardAddrs) + nd, err := NewNode(gen, conf, valKeys, rewardAddrs) + assert.True(t, conf.Sync.Services.IsFullNode()) + assert.True(t, conf.Sync.Services.IsPrunedNode()) require.NoError(t, err) - assert.Equal(t, n.state.LastBlockHash(), hash.UndefHash) + assert.Equal(t, nd.state.LastBlockHash(), hash.UndefHash) - err = n.Start() + err = nd.Start() require.NoError(t, err) - n.Stop() + nd.Stop() } diff --git a/sync/bundle/message/hello.go b/sync/bundle/message/hello.go index 081b3c2e8..5457228a3 100644 --- a/sync/bundle/message/hello.go +++ b/sync/bundle/message/hello.go @@ -27,7 +27,7 @@ type HelloMessage struct { } func NewHelloMessage(pid peer.ID, moniker string, - height uint32, services service.Services, blockHash, genesisHash hash.Hash, + services service.Services, height uint32, blockHash, genesisHash hash.Hash, ) *HelloMessage { return &HelloMessage{ PeerID: pid, diff --git a/sync/bundle/message/hello_test.go b/sync/bundle/message/hello_test.go index f0e149430..d54571f98 100644 --- a/sync/bundle/message/hello_test.go +++ b/sync/bundle/message/hello_test.go @@ -6,6 +6,7 @@ import ( "github.com/pactus-project/pactus/crypto" "github.com/pactus-project/pactus/crypto/bls" + "github.com/pactus-project/pactus/sync/peerset/peer/service" "github.com/pactus-project/pactus/util/errors" "github.com/pactus-project/pactus/util/testsuite" "github.com/stretchr/testify/assert" @@ -21,7 +22,8 @@ func TestHelloMessage(t *testing.T) { t.Run("Invalid signature", func(t *testing.T) { valKey := ts.RandValKey() - m := NewHelloMessage(ts.RandPeerID(), "Oscar", 100, 0, ts.RandHash(), ts.RandHash()) + m := NewHelloMessage(ts.RandPeerID(), "Oscar", service.New(service.FullNode), + ts.RandHeight(), ts.RandHash(), ts.RandHash()) m.Sign([]*bls.ValidatorKey{valKey}) m.Signature = ts.RandBLSSignature() @@ -30,7 +32,8 @@ func TestHelloMessage(t *testing.T) { t.Run("Signature is nil", func(t *testing.T) { valKey := ts.RandValKey() - m := NewHelloMessage(ts.RandPeerID(), "Oscar", 100, 0, ts.RandHash(), ts.RandHash()) + m := NewHelloMessage(ts.RandPeerID(), "Oscar", service.New(service.FullNode), + ts.RandHeight(), ts.RandHash(), ts.RandHash()) m.Sign([]*bls.ValidatorKey{valKey}) m.Signature = nil @@ -39,7 +42,8 @@ func TestHelloMessage(t *testing.T) { t.Run("PublicKeys are empty", func(t *testing.T) { valKey := ts.RandValKey() - m := NewHelloMessage(ts.RandPeerID(), "Oscar", 100, 0, ts.RandHash(), ts.RandHash()) + m := NewHelloMessage(ts.RandPeerID(), "Oscar", service.New(service.FullNode), + ts.RandHeight(), ts.RandHash(), ts.RandHash()) m.Sign([]*bls.ValidatorKey{valKey}) m.PublicKeys = make([]*bls.PublicKey, 0) @@ -50,7 +54,8 @@ func TestHelloMessage(t *testing.T) { time1 := time.Now() myTimeUnixMilli := time1.UnixMilli() - m := NewHelloMessage(ts.RandPeerID(), "Alice", 100, 0, ts.RandHash(), ts.RandHash()) + m := NewHelloMessage(ts.RandPeerID(), "Alice", service.New(service.FullNode), + ts.RandHeight(), ts.RandHash(), ts.RandHash()) assert.LessOrEqual(t, m.MyTimeUnixMilli, time.Now().UnixMilli()) assert.GreaterOrEqual(t, m.MyTimeUnixMilli, myTimeUnixMilli) @@ -58,10 +63,12 @@ func TestHelloMessage(t *testing.T) { t.Run("Ok", func(t *testing.T) { valKey := ts.RandValKey() - m := NewHelloMessage(ts.RandPeerID(), "Alice", 100, 0, ts.RandHash(), ts.RandHash()) + m := NewHelloMessage(ts.RandPeerID(), "Alice", service.New(service.FullNode), + ts.RandHeight(), ts.RandHash(), ts.RandHash()) m.Sign([]*bls.ValidatorKey{valKey}) assert.NoError(t, m.BasicCheck()) assert.Contains(t, m.String(), "Alice") + assert.Contains(t, m.String(), "FULL") }) } diff --git a/sync/config.go b/sync/config.go index 7264672a2..51b95f5e7 100644 --- a/sync/config.go +++ b/sync/config.go @@ -12,23 +12,23 @@ import ( type Config struct { Moniker string `toml:"moniker"` SessionTimeout time.Duration `toml:"session_timeout"` - NodeNetwork bool `toml:"node_network"` Firewall *firewall.Config `toml:"firewall"` // Private configs - MaxSessions int `toml:"-"` - LatestBlockInterval uint32 `toml:"-"` - BlockPerMessage uint32 `toml:"-"` - LatestSupportingVer version.Version `toml:"-"` + MaxSessions int `toml:"-"` + LatestBlockInterval uint32 `toml:"-"` + BlockPerMessage uint32 `toml:"-"` + LatestSupportingVer version.Version `toml:"-"` + Services service.Services `toml:"-"` } func DefaultConfig() *Config { return &Config{ SessionTimeout: time.Second * 10, - NodeNetwork: true, + Services: service.New(service.PrunedNode), BlockPerMessage: 60, MaxSessions: 8, - LatestBlockInterval: 720, + LatestBlockInterval: 10 * 8640, // 10 days, same as default retention blocks in prune node Firewall: firewall.DefaultConfig(), LatestSupportingVer: version.Version{ Major: 1, @@ -47,12 +47,3 @@ func (conf *Config) CacheSize() int { return util.LogScale( int(conf.BlockPerMessage * conf.LatestBlockInterval)) } - -func (conf *Config) Services() service.Services { - s := service.New() - if conf.NodeNetwork { - s.Append(service.Network) - } - - return s -} diff --git a/sync/handler_blocks_request.go b/sync/handler_blocks_request.go index b49196791..69af88314 100644 --- a/sync/handler_blocks_request.go +++ b/sync/handler_blocks_request.go @@ -43,7 +43,7 @@ func (handler *blocksRequestHandler) ParseMessage(m message.Message, pid peer.ID } ourHeight := handler.state.LastBlockHeight() - if !handler.config.NodeNetwork { + if !handler.config.Services.IsFullNode() { if ourHeight > handler.config.LatestBlockInterval && msg.From < ourHeight-handler.config.LatestBlockInterval { response := message.NewBlocksResponseMessage(message.ResponseCodeRejected, fmt.Sprintf("the request height is not acceptable: %v", msg.From), msg.SessionID, 0, nil, nil) diff --git a/sync/handler_blocks_request_test.go b/sync/handler_blocks_request_test.go index 22a4ccc3b..ecbf777f7 100644 --- a/sync/handler_blocks_request_test.go +++ b/sync/handler_blocks_request_test.go @@ -10,15 +10,14 @@ import ( ) func TestBlocksRequestMessages(t *testing.T) { - config := testConfig() - config.NodeNetwork = false + t.Run("NetworkLimited service is enabled", func(t *testing.T) { + config := testConfig() + config.Services = service.Services(service.PrunedNode) - td := setup(t, config) - sid := td.RandInt(100) + td := setup(t, config) + sid := td.RandInt(100) - td.state.CommitTestBlocks(31) - - t.Run("NodeNetwork flag is not set", func(t *testing.T) { + td.state.CommitTestBlocks(31) curHeight := td.state.LastBlockHeight() t.Run("Reject request from unknown peers", func(t *testing.T) { @@ -118,8 +117,14 @@ func TestBlocksRequestMessages(t *testing.T) { }) }) - t.Run("NodeNetwork flag set", func(t *testing.T) { - td.sync.config.NodeNetwork = true + t.Run("Network service is enabled", func(t *testing.T) { + config := testConfig() + config.Services = service.New(service.FullNode) + + td := setup(t, config) + sid := td.RandInt(100) + + td.state.CommitTestBlocks(31) pid := td.addPeer(t, status.StatusKnown, service.New(service.None)) t.Run("Requesting one block", func(t *testing.T) { diff --git a/sync/handler_blocks_response_test.go b/sync/handler_blocks_response_test.go index 42093b6fd..0a31fcdaa 100644 --- a/sync/handler_blocks_response_test.go +++ b/sync/handler_blocks_response_test.go @@ -174,7 +174,6 @@ func makeAliceAndBobNetworks(t *testing.T) *networkAliceBob { networkAlice := network.MockingNetwork(ts, ts.RandPeerID()) networkBob := network.MockingNetwork(ts, ts.RandPeerID()) - configBob.NodeNetwork = true networkAlice.AddAnotherNetwork(networkBob) networkBob.AddAnotherNetwork(networkAlice) diff --git a/sync/handler_hello_test.go b/sync/handler_hello_test.go index f97b9cb8a..50c47bea7 100644 --- a/sync/handler_hello_test.go +++ b/sync/handler_hello_test.go @@ -23,8 +23,8 @@ func TestParsingHelloMessages(t *testing.T) { func(t *testing.T) { valKey := td.RandValKey() pid := td.RandPeerID() - msg := message.NewHelloMessage(pid, "unknown-peer", 0, 0, - td.state.LastBlockHash(), td.state.Genesis().Hash()) + msg := message.NewHelloMessage(pid, "unknown-peer", service.New(service.FullNode), + td.RandHeight(), td.RandHash(), td.state.Genesis().Hash()) msg.Sign([]*bls.ValidatorKey{valKey}) from := td.RandPeerID() @@ -38,8 +38,8 @@ func TestParsingHelloMessages(t *testing.T) { invGenHash := td.RandHash() valKey := td.RandValKey() pid := td.RandPeerID() - msg := message.NewHelloMessage(pid, "bad-genesis", 0, 0, - td.state.LastBlockHash(), invGenHash) + msg := message.NewHelloMessage(pid, "bad-genesis", service.New(service.FullNode), + td.RandHeight(), td.RandHash(), invGenHash) msg.Sign([]*bls.ValidatorKey{valKey}) td.receivingNewMessage(td.sync, msg, pid) @@ -51,10 +51,9 @@ func TestParsingHelloMessages(t *testing.T) { t.Run("Receiving a Hello message from a peer. The time difference is greater than or equal to -10", func(t *testing.T) { valKey := td.RandValKey() - height := td.RandUint32NonZero(td.state.LastBlockHeight()) pid := td.RandPeerID() - msg := message.NewHelloMessage(pid, "kitty", height, service.New(service.Network), - td.state.LastBlockHash(), td.state.Genesis().Hash()) + msg := message.NewHelloMessage(pid, "kitty", service.New(service.FullNode), + td.RandHeight(), td.RandHash(), td.state.Genesis().Hash()) msg.Sign([]*bls.ValidatorKey{valKey}) msg.MyTimeUnixMilli = msg.MyTime().Add(-10 * time.Second).UnixMilli() @@ -67,10 +66,9 @@ func TestParsingHelloMessages(t *testing.T) { t.Run("Receiving Hello message from a peer. Difference is less or equal than 20 seconds.", func(t *testing.T) { valKey := td.RandValKey() - height := td.RandUint32NonZero(td.state.LastBlockHeight()) pid := td.RandPeerID() - msg := message.NewHelloMessage(pid, "kitty", height, service.New(service.Network), - td.state.LastBlockHash(), td.state.Genesis().Hash()) + msg := message.NewHelloMessage(pid, "kitty", service.New(service.FullNode), + td.RandHeight(), td.RandHash(), td.state.Genesis().Hash()) msg.Sign([]*bls.ValidatorKey{valKey}) msg.MyTimeUnixMilli = msg.MyTime().Add(20 * time.Second).UnixMilli() @@ -83,10 +81,9 @@ func TestParsingHelloMessages(t *testing.T) { t.Run("Non supporting version.", func(t *testing.T) { valKey := td.RandValKey() - height := td.RandUint32NonZero(td.state.LastBlockHeight()) pid := td.RandPeerID() - msg := message.NewHelloMessage(pid, "kitty", height, service.New(service.Network), - td.state.LastBlockHash(), td.state.Genesis().Hash()) + msg := message.NewHelloMessage(pid, "kitty", service.New(service.FullNode), + td.RandHeight(), td.RandHash(), td.state.Genesis().Hash()) nodeAgent := version.NodeAgent nodeAgent.Version = version.Version{ Major: 1, @@ -105,10 +102,9 @@ func TestParsingHelloMessages(t *testing.T) { t.Run("Invalid agent.", func(t *testing.T) { valKey := td.RandValKey() - height := td.RandUint32NonZero(td.state.LastBlockHeight()) pid := td.RandPeerID() - msg := message.NewHelloMessage(pid, "kitty", height, service.New(service.Network), - td.state.LastBlockHash(), td.state.Genesis().Hash()) + msg := message.NewHelloMessage(pid, "kitty", service.New(service.FullNode), + td.RandHeight(), td.RandHash(), td.state.Genesis().Hash()) msg.Agent = "invalid-agent" msg.Sign([]*bls.ValidatorKey{valKey}) @@ -121,10 +117,10 @@ func TestParsingHelloMessages(t *testing.T) { t.Run("Receiving Hello message from a peer. It should be acknowledged and updates the peer info", func(t *testing.T) { valKey := td.RandValKey() - height := td.RandUint32NonZero(td.state.LastBlockHeight()) pid := td.RandPeerID() - msg := message.NewHelloMessage(pid, "kitty", height, service.New(service.Network), - td.state.LastBlockHash(), td.state.Genesis().Hash()) + peerHeight := td.RandHeight() + msg := message.NewHelloMessage(pid, "kitty", service.New(service.FullNode), + peerHeight, td.RandHash(), td.state.Genesis().Hash()) msg.Sign([]*bls.ValidatorKey{valKey}) td.receivingNewMessage(td.sync, msg, pid) @@ -141,8 +137,8 @@ func TestParsingHelloMessages(t *testing.T) { assert.Equal(t, p.Moniker, "kitty") assert.Contains(t, p.ConsensusKeys, pub) assert.Equal(t, p.PeerID, pid) - assert.Equal(t, p.Height, height) - assert.True(t, p.HasNetworkService()) + assert.Equal(t, p.Height, peerHeight) + assert.True(t, p.IsFullNode()) }) } @@ -154,5 +150,5 @@ func TestSendingHelloMessage(t *testing.T) { bdl := td.shouldPublishMessageWithThisType(t, message.TypeHello) assert.True(t, util.IsFlagSet(bdl.Flags, bundle.BundleFlagHandshaking)) - assert.True(t, util.IsFlagSet(bdl.Message.(*message.HelloMessage).Services, service.New(service.Network))) + assert.True(t, util.IsFlagSet(bdl.Message.(*message.HelloMessage).Services, service.New(service.FullNode))) } diff --git a/sync/mock.go b/sync/mock.go index 6e52d4be9..542fb182a 100644 --- a/sync/mock.go +++ b/sync/mock.go @@ -30,7 +30,7 @@ func MockingSync(ts *testsuite.TestSuite) *MockSync { "test-peer-1", version.NodeAgent.String(), []*bls.PublicKey{pub1}, - service.New(service.Network)) + service.New(service.FullNode)) ps.UpdateHeight(pid1, ts.RandHeight(), ts.RandHash()) ps.UpdateInfo( diff --git a/sync/peerset/peer/peer.go b/sync/peerset/peer/peer.go index c21b70b50..6de44a115 100644 --- a/sync/peerset/peer/peer.go +++ b/sync/peerset/peer/peer.go @@ -46,8 +46,8 @@ func NewPeer(peerID ID) *Peer { } } -func (p *Peer) HasNetworkService() bool { - return p.Services.IsNetwork() +func (p *Peer) IsFullNode() bool { + return p.Services.IsFullNode() } func (p *Peer) DownloadScore() int { diff --git a/sync/peerset/peer/peer_test.go b/sync/peerset/peer/peer_test.go index b06b9dc08..57eadba25 100644 --- a/sync/peerset/peer/peer_test.go +++ b/sync/peerset/peer/peer_test.go @@ -35,13 +35,14 @@ func TestPeerStatus(t *testing.T) { } } -func TestHasNetworkService(t *testing.T) { +func TestIsFullNode(t *testing.T) { p1 := NewPeer("peer-1") p2 := NewPeer("peer-1") - p2.Services = service.New(service.Network) + p1.Services = service.New(service.PrunedNode) + p2.Services = service.New(service.FullNode) - assert.False(t, p1.HasNetworkService()) - assert.True(t, p2.HasNetworkService()) + assert.False(t, p1.IsFullNode()) + assert.True(t, p2.IsFullNode()) } func TestDownloadScore(t *testing.T) { diff --git a/sync/peerset/peer/service/services.go b/sync/peerset/peer/service/services.go index b02a51ad7..424b3418c 100644 --- a/sync/peerset/peer/service/services.go +++ b/sync/peerset/peer/service/services.go @@ -12,9 +12,13 @@ type ( ) const ( - None Service = 0x00 - Network Service = 0x01 - Foo Service = 0x02 // For future use + None Service = 0x00 + + // FullNode indicates that the node has a full blockchain history. + FullNode Service = 0x01 + + // PrunedNode indicates that the node has a pruned blockchain history. + PrunedNode Service = 0x02 ) func New(flags ...Service) Services { @@ -33,14 +37,14 @@ func (s *Services) Append(flag Service) { func (s Services) String() string { services := "" flags := s - if util.IsFlagSet(flags, Services(Network)) { - services += "NETWORK | " - flags = util.UnsetFlag(flags, Services(Network)) + if util.IsFlagSet(flags, Services(FullNode)) { + services += "FULL | " + flags = util.UnsetFlag(flags, Services(FullNode)) } - if util.IsFlagSet(flags, Services(Foo)) { - services += "FOO | " - flags = util.UnsetFlag(flags, Services(Foo)) + if util.IsFlagSet(flags, Services(PrunedNode)) { + services += "PRUNED | " + flags = util.UnsetFlag(flags, Services(PrunedNode)) } if flags != 0 { @@ -52,10 +56,10 @@ func (s Services) String() string { return services } -func (s Services) IsNetwork() bool { - return util.IsFlagSet(s, Services(Network)) +func (s Services) IsFullNode() bool { + return util.IsFlagSet(s, Services(FullNode)) } -func (s Services) IsFoo() bool { - return util.IsFlagSet(s, Services(Foo)) +func (s Services) IsPrunedNode() bool { + return util.IsFlagSet(s, Services(PrunedNode)) } diff --git a/sync/peerset/peer/service/services_test.go b/sync/peerset/peer/service/services_test.go index cf93b13d3..5ea288e9a 100644 --- a/sync/peerset/peer/service/services_test.go +++ b/sync/peerset/peer/service/services_test.go @@ -8,33 +8,19 @@ import ( func TestServicesString(t *testing.T) { assert.Equal(t, New(None).String(), "") - assert.Equal(t, New(Network).String(), "NETWORK") - assert.Equal(t, New(Foo).String(), "FOO") - assert.Equal(t, New(Network, Foo).String(), "NETWORK | FOO") - assert.Equal(t, New(5).String(), "NETWORK | 4") - assert.Equal(t, New(6).String(), "FOO | 4") + assert.Equal(t, New(FullNode).String(), "FULL") + assert.Equal(t, New(PrunedNode).String(), "PRUNED") + assert.Equal(t, New(FullNode, PrunedNode).String(), "FULL | PRUNED") + assert.Equal(t, New(5).String(), "FULL | 4") + assert.Equal(t, New(6).String(), "PRUNED | 4") } func TestAppend(t *testing.T) { - s := New(Network) - assert.True(t, s.IsNetwork()) - assert.False(t, s.IsFoo()) + s := New(FullNode) + assert.True(t, s.IsFullNode()) + assert.False(t, s.IsPrunedNode()) - s.Append(Foo) - assert.True(t, s.IsNetwork()) - assert.True(t, s.IsFoo()) -} - -func TestIsNetwork(t *testing.T) { - assert.False(t, New(None).IsNetwork()) - assert.True(t, New(Network).IsNetwork()) - assert.False(t, New(Foo).IsNetwork()) - assert.True(t, New(Foo, Network).IsNetwork()) -} - -func TestIsFoo(t *testing.T) { - assert.False(t, New(None).IsFoo()) - assert.False(t, New(Network).IsFoo()) - assert.True(t, New(Foo).IsFoo()) - assert.True(t, New(Foo, Network).IsNetwork()) + s.Append(PrunedNode) + assert.True(t, s.IsFullNode()) + assert.True(t, s.IsPrunedNode()) } diff --git a/sync/peerset/peer_set_test.go b/sync/peerset/peer_set_test.go index 1679fd831..3091f54b4 100644 --- a/sync/peerset/peer_set_test.go +++ b/sync/peerset/peer_set_test.go @@ -40,11 +40,11 @@ func TestPeerSet(t *testing.T) { pid2 := ts.RandPeerID() pid3 := ts.RandPeerID() peerSet.UpdateInfo(pid1, "Moniker1", "Agent1", - []*bls.PublicKey{pk1, pk2}, service.New(service.Network)) + []*bls.PublicKey{pk1, pk2}, service.New(service.FullNode)) peerSet.UpdateInfo(pid2, "Moniker2", "Agent2", []*bls.PublicKey{pk3}, service.New(service.None)) peerSet.UpdateInfo(pid3, "Moniker3", "Agent3", - []*bls.PublicKey{pk4, pk5}, service.New(service.Network)) + []*bls.PublicKey{pk4, pk5}, service.New(service.FullNode)) t.Run("Testing Len", func(t *testing.T) { assert.Equal(t, 3, peerSet.Len()) diff --git a/sync/sync.go b/sync/sync.go index 35f7ca260..29a51fac0 100644 --- a/sync/sync.go +++ b/sync/sync.go @@ -234,7 +234,7 @@ func (sync *synchronizer) PeerSet() *peerset.PeerSet { } func (sync *synchronizer) Services() service.Services { - return sync.config.Services() + return sync.config.Services } func (sync *synchronizer) sayHello(to peer.ID) { @@ -246,8 +246,8 @@ func (sync *synchronizer) sayHello(to peer.ID) { msg := message.NewHelloMessage( sync.SelfID(), sync.config.Moniker, + sync.config.Services, sync.stateHeight(), - sync.config.Services(), sync.state.LastBlockHash(), sync.state.Genesis().Hash(), ) @@ -441,12 +441,12 @@ func (sync *synchronizer) updateBlockchain() { } // downloadBlocks starts downloading blocks from the network. -func (sync *synchronizer) downloadBlocks(from uint32, onlyNodeNetwork bool) { +func (sync *synchronizer) downloadBlocks(from uint32, onlyFullNodes bool) { sync.logger.Debug("downloading blocks", "from", from) for i := sync.peerSet.NumberOfSessions(); i < sync.config.MaxSessions; i++ { count := sync.config.LatestBlockInterval - sent := sync.sendBlockRequestToRandomPeer(from, count, onlyNodeNetwork) + sent := sync.sendBlockRequestToRandomPeer(from, count, onlyFullNodes) if !sent { return } @@ -455,7 +455,7 @@ func (sync *synchronizer) downloadBlocks(from uint32, onlyNodeNetwork bool) { } } -func (sync *synchronizer) sendBlockRequestToRandomPeer(from, count uint32, onlyNodeNetwork bool) bool { +func (sync *synchronizer) sendBlockRequestToRandomPeer(from, count uint32, onlyFullNodes bool) bool { // Prevent downloading blocks that might be cached before for sync.cache.HasBlockInCache(from) { from++ @@ -483,15 +483,15 @@ func (sync *synchronizer) sendBlockRequestToRandomPeer(from, count uint32, onlyN // We haven't completed the handshake with this peer. if !p.Status.IsKnown() { - if onlyNodeNetwork { + if onlyFullNodes { sync.network.CloseConnection(p.PeerID) } continue } - if onlyNodeNetwork && !p.HasNetworkService() { - if onlyNodeNetwork { + if onlyFullNodes && !p.IsFullNode() { + if onlyFullNodes { sync.network.CloseConnection(p.PeerID) } diff --git a/sync/sync_test.go b/sync/sync_test.go index 92c1e84fd..cb06ac23a 100644 --- a/sync/sync_test.go +++ b/sync/sync_test.go @@ -43,12 +43,12 @@ func testConfig() *Config { return &Config{ Moniker: "test", SessionTimeout: time.Second * 1, - NodeNetwork: true, BlockPerMessage: 11, MaxSessions: 8, LatestBlockInterval: 23, Firewall: firewall.DefaultConfig(), LatestSupportingVer: DefaultConfig().LatestSupportingVer, + Services: service.New(service.FullNode, service.PrunedNode), } } @@ -330,7 +330,7 @@ func TestDownload(t *testing.T) { t.Run("try to download blocks and the peer is a network node", func(t *testing.T) { td := setup(t, conf) - pid := td.addPeer(t, status.StatusKnown, service.New(service.Network)) + pid := td.addPeer(t, status.StatusKnown, service.New(service.FullNode)) blk, cert := td.GenerateTestBlock(td.RandHeight()) baMsg := message.NewBlockAnnounceMessage(blk, cert) td.receivingNewMessage(td.sync, baMsg, pid) diff --git a/tests/main_test.go b/tests/main_test.go index 749327dd6..854e1f328 100644 --- a/tests/main_test.go +++ b/tests/main_test.go @@ -81,7 +81,6 @@ func TestMain(m *testing.M) { tConfigs[i].Logger.Levels["_consensus"] = "info" tConfigs[i].Logger.Levels["_network"] = "info" tConfigs[i].Logger.Levels["_pool"] = "info" - tConfigs[i].Sync.NodeNetwork = false tConfigs[i].Sync.Firewall.BannedNets = make([]string, 0) tConfigs[i].Sync.LatestBlockInterval = 10 tConfigs[i].Network.EnableMdns = true @@ -98,7 +97,6 @@ func TestMain(m *testing.M) { tConfigs[i].GRPC.Enable = false if i == 0 { - tConfigs[i].Sync.NodeNetwork = true tConfigs[i].GRPC.Enable = true tConfigs[i].GRPC.Listen = tGRPCAddress } diff --git a/www/grpc/gen/dart/network.pb.dart b/www/grpc/gen/dart/network.pb.dart index 9ea913ccc..6f61b6a97 100644 --- a/www/grpc/gen/dart/network.pb.dart +++ b/www/grpc/gen/dart/network.pb.dart @@ -282,8 +282,8 @@ class GetNodeInfoResponse extends $pb.GeneratedMessage { ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'peerId') ..a<$fixnum.Int64>(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'startedAt', $pb.PbFieldType.OU6, defaultOrMaker: $fixnum.Int64.ZERO) ..aOS(5, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'reachability') - ..p<$core.int>(6, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'services', $pb.PbFieldType.K3) - ..pPS(7, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'servicesNames') + ..a<$core.int>(6, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'services', $pb.PbFieldType.O3) + ..aOS(7, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'servicesNames') ..pPS(8, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'localAddrs') ..pPS(9, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'protocols') ..a<$core.double>(13, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'clockOffset', $pb.PbFieldType.OD) @@ -298,8 +298,8 @@ class GetNodeInfoResponse extends $pb.GeneratedMessage { $core.String? peerId, $fixnum.Int64? startedAt, $core.String? reachability, - $core.Iterable<$core.int>? services, - $core.Iterable<$core.String>? servicesNames, + $core.int? services, + $core.String? servicesNames, $core.Iterable<$core.String>? localAddrs, $core.Iterable<$core.String>? protocols, $core.double? clockOffset, @@ -322,10 +322,10 @@ class GetNodeInfoResponse extends $pb.GeneratedMessage { _result.reachability = reachability; } if (services != null) { - _result.services.addAll(services); + _result.services = services; } if (servicesNames != null) { - _result.servicesNames.addAll(servicesNames); + _result.servicesNames = servicesNames; } if (localAddrs != null) { _result.localAddrs.addAll(localAddrs); @@ -408,10 +408,22 @@ class GetNodeInfoResponse extends $pb.GeneratedMessage { void clearReachability() => clearField(5); @$pb.TagNumber(6) - $core.List<$core.int> get services => $_getList(5); + $core.int get services => $_getIZ(5); + @$pb.TagNumber(6) + set services($core.int v) { $_setSignedInt32(5, v); } + @$pb.TagNumber(6) + $core.bool hasServices() => $_has(5); + @$pb.TagNumber(6) + void clearServices() => clearField(6); @$pb.TagNumber(7) - $core.List<$core.String> get servicesNames => $_getList(6); + $core.String get servicesNames => $_getSZ(6); + @$pb.TagNumber(7) + set servicesNames($core.String v) { $_setString(6, v); } + @$pb.TagNumber(7) + $core.bool hasServicesNames() => $_has(6); + @$pb.TagNumber(7) + void clearServicesNames() => clearField(7); @$pb.TagNumber(8) $core.List<$core.String> get localAddrs => $_getList(7); diff --git a/www/grpc/gen/dart/network.pbjson.dart b/www/grpc/gen/dart/network.pbjson.dart index a6466da55..bbebe63f5 100644 --- a/www/grpc/gen/dart/network.pbjson.dart +++ b/www/grpc/gen/dart/network.pbjson.dart @@ -83,8 +83,8 @@ const GetNodeInfoResponse$json = const { const {'1': 'peer_id', '3': 3, '4': 1, '5': 9, '10': 'peerId'}, const {'1': 'started_at', '3': 4, '4': 1, '5': 4, '10': 'startedAt'}, const {'1': 'reachability', '3': 5, '4': 1, '5': 9, '10': 'reachability'}, - const {'1': 'services', '3': 6, '4': 3, '5': 5, '10': 'services'}, - const {'1': 'services_names', '3': 7, '4': 3, '5': 9, '10': 'servicesNames'}, + const {'1': 'services', '3': 6, '4': 1, '5': 5, '10': 'services'}, + const {'1': 'services_names', '3': 7, '4': 1, '5': 9, '10': 'servicesNames'}, const {'1': 'local_addrs', '3': 8, '4': 3, '5': 9, '10': 'localAddrs'}, const {'1': 'protocols', '3': 9, '4': 3, '5': 9, '10': 'protocols'}, const {'1': 'clock_offset', '3': 13, '4': 1, '5': 1, '10': 'clockOffset'}, @@ -93,7 +93,7 @@ const GetNodeInfoResponse$json = const { }; /// Descriptor for `GetNodeInfoResponse`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List getNodeInfoResponseDescriptor = $convert.base64Decode('ChNHZXROb2RlSW5mb1Jlc3BvbnNlEhgKB21vbmlrZXIYASABKAlSB21vbmlrZXISFAoFYWdlbnQYAiABKAlSBWFnZW50EhcKB3BlZXJfaWQYAyABKAlSBnBlZXJJZBIdCgpzdGFydGVkX2F0GAQgASgEUglzdGFydGVkQXQSIgoMcmVhY2hhYmlsaXR5GAUgASgJUgxyZWFjaGFiaWxpdHkSGgoIc2VydmljZXMYBiADKAVSCHNlcnZpY2VzEiUKDnNlcnZpY2VzX25hbWVzGAcgAygJUg1zZXJ2aWNlc05hbWVzEh8KC2xvY2FsX2FkZHJzGAggAygJUgpsb2NhbEFkZHJzEhwKCXByb3RvY29scxgJIAMoCVIJcHJvdG9jb2xzEiEKDGNsb2NrX29mZnNldBgNIAEoAVILY2xvY2tPZmZzZXQSPwoPY29ubmVjdGlvbl9pbmZvGA4gASgLMhYucGFjdHVzLkNvbm5lY3Rpb25JbmZvUg5jb25uZWN0aW9uSW5mbw=='); +final $typed_data.Uint8List getNodeInfoResponseDescriptor = $convert.base64Decode('ChNHZXROb2RlSW5mb1Jlc3BvbnNlEhgKB21vbmlrZXIYASABKAlSB21vbmlrZXISFAoFYWdlbnQYAiABKAlSBWFnZW50EhcKB3BlZXJfaWQYAyABKAlSBnBlZXJJZBIdCgpzdGFydGVkX2F0GAQgASgEUglzdGFydGVkQXQSIgoMcmVhY2hhYmlsaXR5GAUgASgJUgxyZWFjaGFiaWxpdHkSGgoIc2VydmljZXMYBiABKAVSCHNlcnZpY2VzEiUKDnNlcnZpY2VzX25hbWVzGAcgASgJUg1zZXJ2aWNlc05hbWVzEh8KC2xvY2FsX2FkZHJzGAggAygJUgpsb2NhbEFkZHJzEhwKCXByb3RvY29scxgJIAMoCVIJcHJvdG9jb2xzEiEKDGNsb2NrX29mZnNldBgNIAEoAVILY2xvY2tPZmZzZXQSPwoPY29ubmVjdGlvbl9pbmZvGA4gASgLMhYucGFjdHVzLkNvbm5lY3Rpb25JbmZvUg5jb25uZWN0aW9uSW5mbw=='); @$core.Deprecated('Use peerInfoDescriptor instead') const PeerInfo$json = const { '1': 'PeerInfo', diff --git a/www/grpc/gen/docs/grpc.md b/www/grpc/gen/docs/grpc.md index 8e11dd6e3..79f76ae0b 100644 --- a/www/grpc/gen/docs/grpc.md +++ b/www/grpc/gen/docs/grpc.md @@ -2363,14 +2363,14 @@ Message has no fields.
- * List of services provided by the node. + * A bitfield indicating the services provided by the node. ** - *
repeated int32 services = 6 [json_name = "services"];
- * @return A list containing the services.
- */
- java.util.List- * List of services provided by the node. - *- * - *
repeated int32 services = 6 [json_name = "services"];
- * @return The count of services.
- */
- int getServicesCount();
- /**
- * - * List of services provided by the node. - *- * - *
repeated int32 services = 6 [json_name = "services"];
- * @param index The index of the element to return.
- * @return The services at the given index.
+ * int32 services = 6 [json_name = "services"];
+ * @return The services.
*/
- int getServices(int index);
+ int getServices();
/**
* * Names of services provided by the node. ** - *
repeated string services_names = 7 [json_name = "servicesNames"];
- * @return A list containing the servicesNames.
- */
- java.util.List- * Names of services provided by the node. - *- * - *
repeated string services_names = 7 [json_name = "servicesNames"];
- * @return The count of servicesNames.
- */
- int getServicesNamesCount();
- /**
- * - * Names of services provided by the node. - *- * - *
repeated string services_names = 7 [json_name = "servicesNames"];
- * @param index The index of the element to return.
- * @return The servicesNames at the given index.
+ * string services_names = 7 [json_name = "servicesNames"];
+ * @return The servicesNames.
*/
- java.lang.String getServicesNames(int index);
+ java.lang.String getServicesNames();
/**
* * Names of services provided by the node. ** - *
repeated string services_names = 7 [json_name = "servicesNames"];
- * @param index The index of the value to return.
- * @return The bytes of the servicesNames at the given index.
+ * string services_names = 7 [json_name = "servicesNames"];
+ * @return The bytes for servicesNames.
*/
com.google.protobuf.ByteString
- getServicesNamesBytes(int index);
+ getServicesNamesBytes();
/**
* @@ -3988,8 +3948,7 @@ private GetNodeInfoResponse() { agent_ = ""; peerId_ = ""; reachability_ = ""; - services_ = emptyIntList(); - servicesNames_ = com.google.protobuf.LazyStringArrayList.EMPTY; + servicesNames_ = ""; localAddrs_ = com.google.protobuf.LazyStringArrayList.EMPTY; protocols_ = com.google.protobuf.LazyStringArrayList.EMPTY; } @@ -4219,94 +4178,64 @@ public java.lang.String getReachability() { } public static final int SERVICES_FIELD_NUMBER = 6; - private com.google.protobuf.Internal.IntList services_; + private int services_; /** ** - *- * List of services provided by the node. + * A bitfield indicating the services provided by the node. ** - *repeated int32 services = 6 [json_name = "services"];
- * @return A list containing the services. + *int32 services = 6 [json_name = "services"];
+ * @return The services. */ @java.lang.Override - public java.util.List- getServicesList() { + public int getServices() { return services_; } - /** - * - * List of services provided by the node. - *- * - *repeated int32 services = 6 [json_name = "services"];
- * @return The count of services. - */ - public int getServicesCount() { - return services_.size(); - } - /** - *- * List of services provided by the node. - *- * - *repeated int32 services = 6 [json_name = "services"];
- * @param index The index of the element to return. - * @return The services at the given index. - */ - public int getServices(int index) { - return services_.getInt(index); - } - private int servicesMemoizedSerializedSize = -1; public static final int SERVICES_NAMES_FIELD_NUMBER = 7; - private com.google.protobuf.LazyStringList servicesNames_; - /** - *- * Names of services provided by the node. - *- * - *repeated string services_names = 7 [json_name = "servicesNames"];
- * @return A list containing the servicesNames. - */ - public com.google.protobuf.ProtocolStringList - getServicesNamesList() { - return servicesNames_; - } - /** - *- * Names of services provided by the node. - *- * - *repeated string services_names = 7 [json_name = "servicesNames"];
- * @return The count of servicesNames. - */ - public int getServicesNamesCount() { - return servicesNames_.size(); - } + private volatile java.lang.Object servicesNames_; /** ** Names of services provided by the node. ** - *repeated string services_names = 7 [json_name = "servicesNames"];
- * @param index The index of the element to return. - * @return The servicesNames at the given index. + *string services_names = 7 [json_name = "servicesNames"];
+ * @return The servicesNames. */ - public java.lang.String getServicesNames(int index) { - return servicesNames_.get(index); + @java.lang.Override + public java.lang.String getServicesNames() { + java.lang.Object ref = servicesNames_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + servicesNames_ = s; + return s; + } } /** ** Names of services provided by the node. ** - *repeated string services_names = 7 [json_name = "servicesNames"];
- * @param index The index of the value to return. - * @return The bytes of the servicesNames at the given index. + *string services_names = 7 [json_name = "servicesNames"];
+ * @return The bytes for servicesNames. */ + @java.lang.Override public com.google.protobuf.ByteString - getServicesNamesBytes(int index) { - return servicesNames_.getByteString(index); + getServicesNamesBytes() { + java.lang.Object ref = servicesNames_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + servicesNames_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } } public static final int LOCAL_ADDRS_FIELD_NUMBER = 8; @@ -4478,7 +4407,6 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - getSerializedSize(); if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(moniker_)) { com.google.protobuf.GeneratedMessageV3.writeString(output, 1, moniker_); } @@ -4494,15 +4422,11 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(reachability_)) { com.google.protobuf.GeneratedMessageV3.writeString(output, 5, reachability_); } - if (getServicesList().size() > 0) { - output.writeUInt32NoTag(50); - output.writeUInt32NoTag(servicesMemoizedSerializedSize); - } - for (int i = 0; i < services_.size(); i++) { - output.writeInt32NoTag(services_.getInt(i)); + if (services_ != 0) { + output.writeInt32(6, services_); } - for (int i = 0; i < servicesNames_.size(); i++) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 7, servicesNames_.getRaw(i)); + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(servicesNames_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 7, servicesNames_); } for (int i = 0; i < localAddrs_.size(); i++) { com.google.protobuf.GeneratedMessageV3.writeString(output, 8, localAddrs_.getRaw(i)); @@ -4541,27 +4465,12 @@ public int getSerializedSize() { if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(reachability_)) { size += com.google.protobuf.GeneratedMessageV3.computeStringSize(5, reachability_); } - { - int dataSize = 0; - for (int i = 0; i < services_.size(); i++) { - dataSize += com.google.protobuf.CodedOutputStream - .computeInt32SizeNoTag(services_.getInt(i)); - } - size += dataSize; - if (!getServicesList().isEmpty()) { - size += 1; - size += com.google.protobuf.CodedOutputStream - .computeInt32SizeNoTag(dataSize); - } - servicesMemoizedSerializedSize = dataSize; + if (services_ != 0) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(6, services_); } - { - int dataSize = 0; - for (int i = 0; i < servicesNames_.size(); i++) { - dataSize += computeStringSizeNoTag(servicesNames_.getRaw(i)); - } - size += dataSize; - size += 1 * getServicesNamesList().size(); + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(servicesNames_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(7, servicesNames_); } { int dataSize = 0; @@ -4612,10 +4521,10 @@ public boolean equals(final java.lang.Object obj) { != other.getStartedAt()) return false; if (!getReachability() .equals(other.getReachability())) return false; - if (!getServicesList() - .equals(other.getServicesList())) return false; - if (!getServicesNamesList() - .equals(other.getServicesNamesList())) return false; + if (getServices() + != other.getServices()) return false; + if (!getServicesNames() + .equals(other.getServicesNames())) return false; if (!getLocalAddrsList() .equals(other.getLocalAddrsList())) return false; if (!getProtocolsList() @@ -4650,14 +4559,10 @@ public int hashCode() { getStartedAt()); hash = (37 * hash) + REACHABILITY_FIELD_NUMBER; hash = (53 * hash) + getReachability().hashCode(); - if (getServicesCount() > 0) { - hash = (37 * hash) + SERVICES_FIELD_NUMBER; - hash = (53 * hash) + getServicesList().hashCode(); - } - if (getServicesNamesCount() > 0) { - hash = (37 * hash) + SERVICES_NAMES_FIELD_NUMBER; - hash = (53 * hash) + getServicesNamesList().hashCode(); - } + hash = (37 * hash) + SERVICES_FIELD_NUMBER; + hash = (53 * hash) + getServices(); + hash = (37 * hash) + SERVICES_NAMES_FIELD_NUMBER; + hash = (53 * hash) + getServicesNames().hashCode(); if (getLocalAddrsCount() > 0) { hash = (37 * hash) + LOCAL_ADDRS_FIELD_NUMBER; hash = (53 * hash) + getLocalAddrsList().hashCode(); @@ -4815,14 +4720,14 @@ public Builder clear() { reachability_ = ""; - services_ = emptyIntList(); - bitField0_ = (bitField0_ & ~0x00000001); - servicesNames_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000002); + services_ = 0; + + servicesNames_ = ""; + localAddrs_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000004); + bitField0_ = (bitField0_ & ~0x00000001); protocols_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000008); + bitField0_ = (bitField0_ & ~0x00000002); clockOffset_ = 0D; if (connectionInfoBuilder_ == null) { @@ -4863,24 +4768,16 @@ public pactus.network.NetworkOuterClass.GetNodeInfoResponse buildPartial() { result.peerId_ = peerId_; result.startedAt_ = startedAt_; result.reachability_ = reachability_; - if (((bitField0_ & 0x00000001) != 0)) { - services_.makeImmutable(); - bitField0_ = (bitField0_ & ~0x00000001); - } result.services_ = services_; - if (((bitField0_ & 0x00000002) != 0)) { - servicesNames_ = servicesNames_.getUnmodifiableView(); - bitField0_ = (bitField0_ & ~0x00000002); - } result.servicesNames_ = servicesNames_; - if (((bitField0_ & 0x00000004) != 0)) { + if (((bitField0_ & 0x00000001) != 0)) { localAddrs_ = localAddrs_.getUnmodifiableView(); - bitField0_ = (bitField0_ & ~0x00000004); + bitField0_ = (bitField0_ & ~0x00000001); } result.localAddrs_ = localAddrs_; - if (((bitField0_ & 0x00000008) != 0)) { + if (((bitField0_ & 0x00000002) != 0)) { protocols_ = protocols_.getUnmodifiableView(); - bitField0_ = (bitField0_ & ~0x00000008); + bitField0_ = (bitField0_ & ~0x00000002); } result.protocols_ = protocols_; result.clockOffset_ = clockOffset_; @@ -4956,30 +4853,17 @@ public Builder mergeFrom(pactus.network.NetworkOuterClass.GetNodeInfoResponse ot reachability_ = other.reachability_; onChanged(); } - if (!other.services_.isEmpty()) { - if (services_.isEmpty()) { - services_ = other.services_; - bitField0_ = (bitField0_ & ~0x00000001); - } else { - ensureServicesIsMutable(); - services_.addAll(other.services_); - } - onChanged(); + if (other.getServices() != 0) { + setServices(other.getServices()); } - if (!other.servicesNames_.isEmpty()) { - if (servicesNames_.isEmpty()) { - servicesNames_ = other.servicesNames_; - bitField0_ = (bitField0_ & ~0x00000002); - } else { - ensureServicesNamesIsMutable(); - servicesNames_.addAll(other.servicesNames_); - } + if (!other.getServicesNames().isEmpty()) { + servicesNames_ = other.servicesNames_; onChanged(); } if (!other.localAddrs_.isEmpty()) { if (localAddrs_.isEmpty()) { localAddrs_ = other.localAddrs_; - bitField0_ = (bitField0_ & ~0x00000004); + bitField0_ = (bitField0_ & ~0x00000001); } else { ensureLocalAddrsIsMutable(); localAddrs_.addAll(other.localAddrs_); @@ -4989,7 +4873,7 @@ public Builder mergeFrom(pactus.network.NetworkOuterClass.GetNodeInfoResponse ot if (!other.protocols_.isEmpty()) { if (protocols_.isEmpty()) { protocols_ = other.protocols_; - bitField0_ = (bitField0_ & ~0x00000008); + bitField0_ = (bitField0_ & ~0x00000002); } else { ensureProtocolsIsMutable(); protocols_.addAll(other.protocols_); @@ -5054,25 +4938,13 @@ public Builder mergeFrom( break; } // case 42 case 48: { - int v = input.readInt32(); - ensureServicesIsMutable(); - services_.addInt(v); + services_ = input.readInt32(); + break; } // case 48 - case 50: { - int length = input.readRawVarint32(); - int limit = input.pushLimit(length); - ensureServicesIsMutable(); - while (input.getBytesUntilLimit() > 0) { - services_.addInt(input.readInt32()); - } - input.popLimit(limit); - break; - } // case 50 case 58: { - java.lang.String s = input.readStringRequireUtf8(); - ensureServicesNamesIsMutable(); - servicesNames_.add(s); + servicesNames_ = input.readStringRequireUtf8(); + break; } // case 58 case 66: { @@ -5543,221 +5415,107 @@ public Builder setReachabilityBytes( return this; } - private com.google.protobuf.Internal.IntList services_ = emptyIntList(); - private void ensureServicesIsMutable() { - if (!((bitField0_ & 0x00000001) != 0)) { - services_ = mutableCopy(services_); - bitField0_ |= 0x00000001; - } - } - /** - *- * List of services provided by the node. - *- * - *repeated int32 services = 6 [json_name = "services"];
- * @return A list containing the services. - */ - public java.util.List- getServicesList() { - return ((bitField0_ & 0x00000001) != 0) ? - java.util.Collections.unmodifiableList(services_) : services_; - } - /** - * - * List of services provided by the node. - *- * - *repeated int32 services = 6 [json_name = "services"];
- * @return The count of services. - */ - public int getServicesCount() { - return services_.size(); - } + private int services_ ; /** *- * List of services provided by the node. + * A bitfield indicating the services provided by the node. ** - *repeated int32 services = 6 [json_name = "services"];
- * @param index The index of the element to return. - * @return The services at the given index. + *int32 services = 6 [json_name = "services"];
+ * @return The services. */ - public int getServices(int index) { - return services_.getInt(index); + @java.lang.Override + public int getServices() { + return services_; } /** *- * List of services provided by the node. + * A bitfield indicating the services provided by the node. ** - *repeated int32 services = 6 [json_name = "services"];
- * @param index The index to set the value at. + *int32 services = 6 [json_name = "services"];
* @param value The services to set. * @return This builder for chaining. */ - public Builder setServices( - int index, int value) { - ensureServicesIsMutable(); - services_.setInt(index, value); - onChanged(); - return this; - } - /** - *- * List of services provided by the node. - *- * - *repeated int32 services = 6 [json_name = "services"];
- * @param value The services to add. - * @return This builder for chaining. - */ - public Builder addServices(int value) { - ensureServicesIsMutable(); - services_.addInt(value); - onChanged(); - return this; - } - /** - *- * List of services provided by the node. - *- * - *repeated int32 services = 6 [json_name = "services"];
- * @param values The services to add. - * @return This builder for chaining. - */ - public Builder addAllServices( - java.lang.Iterable extends java.lang.Integer> values) { - ensureServicesIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, services_); + public Builder setServices(int value) { + + services_ = value; onChanged(); return this; } /** *- * List of services provided by the node. + * A bitfield indicating the services provided by the node. ** - *repeated int32 services = 6 [json_name = "services"];
+ *int32 services = 6 [json_name = "services"];
* @return This builder for chaining. */ public Builder clearServices() { - services_ = emptyIntList(); - bitField0_ = (bitField0_ & ~0x00000001); + + services_ = 0; onChanged(); return this; } - private com.google.protobuf.LazyStringList servicesNames_ = com.google.protobuf.LazyStringArrayList.EMPTY; - private void ensureServicesNamesIsMutable() { - if (!((bitField0_ & 0x00000002) != 0)) { - servicesNames_ = new com.google.protobuf.LazyStringArrayList(servicesNames_); - bitField0_ |= 0x00000002; - } - } + private java.lang.Object servicesNames_ = ""; /** ** Names of services provided by the node. ** - *repeated string services_names = 7 [json_name = "servicesNames"];
- * @return A list containing the servicesNames. + *string services_names = 7 [json_name = "servicesNames"];
+ * @return The servicesNames. */ - public com.google.protobuf.ProtocolStringList - getServicesNamesList() { - return servicesNames_.getUnmodifiableView(); - } - /** - *- * Names of services provided by the node. - *- * - *repeated string services_names = 7 [json_name = "servicesNames"];
- * @return The count of servicesNames. - */ - public int getServicesNamesCount() { - return servicesNames_.size(); - } - /** - *- * Names of services provided by the node. - *- * - *repeated string services_names = 7 [json_name = "servicesNames"];
- * @param index The index of the element to return. - * @return The servicesNames at the given index. - */ - public java.lang.String getServicesNames(int index) { - return servicesNames_.get(index); + public java.lang.String getServicesNames() { + java.lang.Object ref = servicesNames_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + servicesNames_ = s; + return s; + } else { + return (java.lang.String) ref; + } } /** ** Names of services provided by the node. ** - *repeated string services_names = 7 [json_name = "servicesNames"];
- * @param index The index of the value to return. - * @return The bytes of the servicesNames at the given index. + *string services_names = 7 [json_name = "servicesNames"];
+ * @return The bytes for servicesNames. */ public com.google.protobuf.ByteString - getServicesNamesBytes(int index) { - return servicesNames_.getByteString(index); + getServicesNamesBytes() { + java.lang.Object ref = servicesNames_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + servicesNames_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } } /** ** Names of services provided by the node. ** - *repeated string services_names = 7 [json_name = "servicesNames"];
- * @param index The index to set the value at. + *string services_names = 7 [json_name = "servicesNames"];
* @param value The servicesNames to set. * @return This builder for chaining. */ public Builder setServicesNames( - int index, java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - ensureServicesNamesIsMutable(); - servicesNames_.set(index, value); - onChanged(); - return this; - } - /** - *- * Names of services provided by the node. - *- * - *repeated string services_names = 7 [json_name = "servicesNames"];
- * @param value The servicesNames to add. - * @return This builder for chaining. - */ - public Builder addServicesNames( java.lang.String value) { if (value == null) { throw new NullPointerException(); } - ensureServicesNamesIsMutable(); - servicesNames_.add(value); - onChanged(); - return this; - } - /** - *- * Names of services provided by the node. - *- * - *repeated string services_names = 7 [json_name = "servicesNames"];
- * @param values The servicesNames to add. - * @return This builder for chaining. - */ - public Builder addAllServicesNames( - java.lang.Iterablevalues) { - ensureServicesNamesIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, servicesNames_); + + servicesNames_ = value; onChanged(); return this; } @@ -5766,12 +5524,12 @@ public Builder addAllServicesNames( * Names of services provided by the node. *
repeated string services_names = 7 [json_name = "servicesNames"];
+ * string services_names = 7 [json_name = "servicesNames"];
* @return This builder for chaining.
*/
public Builder clearServicesNames() {
- servicesNames_ = com.google.protobuf.LazyStringArrayList.EMPTY;
- bitField0_ = (bitField0_ & ~0x00000002);
+
+ servicesNames_ = getDefaultInstance().getServicesNames();
onChanged();
return this;
}
@@ -5780,27 +5538,27 @@ public Builder clearServicesNames() {
* Names of services provided by the node.
*
*
- * repeated string services_names = 7 [json_name = "servicesNames"];
- * @param value The bytes of the servicesNames to add.
+ * string services_names = 7 [json_name = "servicesNames"];
+ * @param value The bytes for servicesNames to set.
* @return This builder for chaining.
*/
- public Builder addServicesNamesBytes(
+ public Builder setServicesNamesBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
- ensureServicesNamesIsMutable();
- servicesNames_.add(value);
+
+ servicesNames_ = value;
onChanged();
return this;
}
private com.google.protobuf.LazyStringList localAddrs_ = com.google.protobuf.LazyStringArrayList.EMPTY;
private void ensureLocalAddrsIsMutable() {
- if (!((bitField0_ & 0x00000004) != 0)) {
+ if (!((bitField0_ & 0x00000001) != 0)) {
localAddrs_ = new com.google.protobuf.LazyStringArrayList(localAddrs_);
- bitField0_ |= 0x00000004;
+ bitField0_ |= 0x00000001;
}
}
/**
@@ -5917,7 +5675,7 @@ public Builder addAllLocalAddrs(
*/
public Builder clearLocalAddrs() {
localAddrs_ = com.google.protobuf.LazyStringArrayList.EMPTY;
- bitField0_ = (bitField0_ & ~0x00000004);
+ bitField0_ = (bitField0_ & ~0x00000001);
onChanged();
return this;
}
@@ -5944,9 +5702,9 @@ public Builder addLocalAddrsBytes(
private com.google.protobuf.LazyStringList protocols_ = com.google.protobuf.LazyStringArrayList.EMPTY;
private void ensureProtocolsIsMutable() {
- if (!((bitField0_ & 0x00000008) != 0)) {
+ if (!((bitField0_ & 0x00000002) != 0)) {
protocols_ = new com.google.protobuf.LazyStringArrayList(protocols_);
- bitField0_ |= 0x00000008;
+ bitField0_ |= 0x00000002;
}
}
/**
@@ -6063,7 +5821,7 @@ public Builder addAllProtocols(
*/
public Builder clearProtocols() {
protocols_ = com.google.protobuf.LazyStringArrayList.EMPTY;
- bitField0_ = (bitField0_ & ~0x00000008);
+ bitField0_ = (bitField0_ & ~0x00000002);
onChanged();
return this;
}
@@ -10326,7 +10084,7 @@ public pactus.network.NetworkOuterClass.PeerInfo getDefaultInstanceForType() {
"nt\030\002 \001(\tR\005agent\022\027\n\007peer_id\030\003 \001(\tR\006peerId" +
"\022\035\n\nstarted_at\030\004 \001(\004R\tstartedAt\022\"\n\014reach" +
"ability\030\005 \001(\tR\014reachability\022\032\n\010services\030" +
- "\006 \003(\005R\010services\022%\n\016services_names\030\007 \003(\tR" +
+ "\006 \001(\005R\010services\022%\n\016services_names\030\007 \001(\tR" +
"\rservicesNames\022\037\n\013local_addrs\030\010 \003(\tR\nloc" +
"alAddrs\022\034\n\tprotocols\030\t \003(\tR\tprotocols\022!\n" +
"\014clock_offset\030\r \001(\001R\013clockOffset\022?\n\017conn" +
diff --git a/www/grpc/gen/js/network_pb.js b/www/grpc/gen/js/network_pb.js
index 54753c111..6e10b07af 100644
--- a/www/grpc/gen/js/network_pb.js
+++ b/www/grpc/gen/js/network_pb.js
@@ -928,7 +928,7 @@ proto.pactus.ConnectionInfo.prototype.setOutboundConnections = function(value) {
* @private {!Array