Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
474aa924
Commit
474aa924
authored
Apr 14, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p2p: added limiter function to limit package broadcasting
parent
b7e1b686
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
0 deletions
+13
-0
server.go
p2p/server.go
+13
-0
No files found.
p2p/server.go
View file @
474aa924
...
...
@@ -136,6 +136,12 @@ func (srv *Server) SuggestPeer(n *discover.Node) {
// Broadcast sends an RLP-encoded message to all connected peers.
// This method is deprecated and will be removed later.
func
(
srv
*
Server
)
Broadcast
(
protocol
string
,
code
uint64
,
data
interface
{})
error
{
return
srv
.
BroadcastLimited
(
protocol
,
code
,
func
(
i
float64
)
float64
{
return
i
},
data
)
}
// BroadcastsRange an RLP-encoded message to a random set of peers using the limit function to limit the amount
// of peers.
func
(
srv
*
Server
)
BroadcastLimited
(
protocol
string
,
code
uint64
,
limit
func
(
float64
)
float64
,
data
interface
{})
error
{
var
payload
[]
byte
if
data
!=
nil
{
var
err
error
...
...
@@ -146,7 +152,13 @@ func (srv *Server) Broadcast(protocol string, code uint64, data interface{}) err
}
srv
.
lock
.
RLock
()
defer
srv
.
lock
.
RUnlock
()
i
,
max
:=
0
,
int
(
limit
(
float64
(
len
(
srv
.
peers
))))
for
_
,
peer
:=
range
srv
.
peers
{
if
i
>=
max
{
break
}
if
peer
!=
nil
{
var
msg
=
Msg
{
Code
:
code
}
if
data
!=
nil
{
...
...
@@ -154,6 +166,7 @@ func (srv *Server) Broadcast(protocol string, code uint64, data interface{}) err
msg
.
Size
=
uint32
(
len
(
payload
))
}
peer
.
writeProtoMsg
(
protocol
,
msg
)
i
++
}
}
return
nil
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment