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
91726e8a
Unverified
Commit
91726e8a
authored
Mar 16, 2021
by
Felföldi Zsolt
Committed by
GitHub
Mar 16, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
les: allow either full enode strings or raw hex ids in the API (#22423)
parent
6d9707a4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
6 deletions
+45
-6
api.go
les/api.go
+45
-6
No files found.
les/api.go
View file @
91726e8a
...
...
@@ -49,6 +49,18 @@ func NewPrivateLightServerAPI(server *LesServer) *PrivateLightServerAPI {
}
}
// parseNode parses either an enode address a raw hex node id
func
parseNode
(
node
string
)
(
enode
.
ID
,
error
)
{
if
id
,
err
:=
enode
.
ParseID
(
node
);
err
==
nil
{
return
id
,
nil
}
if
node
,
err
:=
enode
.
Parse
(
enode
.
ValidSchemes
,
node
);
err
==
nil
{
return
node
.
ID
(),
nil
}
else
{
return
enode
.
ID
{},
err
}
}
// ServerInfo returns global server parameters
func
(
api
*
PrivateLightServerAPI
)
ServerInfo
()
map
[
string
]
interface
{}
{
res
:=
make
(
map
[
string
]
interface
{})
...
...
@@ -59,7 +71,14 @@ func (api *PrivateLightServerAPI) ServerInfo() map[string]interface{} {
}
// ClientInfo returns information about clients listed in the ids list or matching the given tags
func
(
api
*
PrivateLightServerAPI
)
ClientInfo
(
ids
[]
enode
.
ID
)
map
[
enode
.
ID
]
map
[
string
]
interface
{}
{
func
(
api
*
PrivateLightServerAPI
)
ClientInfo
(
nodes
[]
string
)
map
[
enode
.
ID
]
map
[
string
]
interface
{}
{
var
ids
[]
enode
.
ID
for
_
,
node
:=
range
nodes
{
if
id
,
err
:=
parseNode
(
node
);
err
==
nil
{
ids
=
append
(
ids
,
id
)
}
}
res
:=
make
(
map
[
enode
.
ID
]
map
[
string
]
interface
{})
api
.
server
.
clientPool
.
forClients
(
ids
,
func
(
client
*
clientInfo
)
{
res
[
client
.
node
.
ID
()]
=
api
.
clientInfo
(
client
)
...
...
@@ -159,8 +178,18 @@ func (api *PrivateLightServerAPI) setParams(params map[string]interface{}, clien
// SetClientParams sets client parameters for all clients listed in the ids list
// or all connected clients if the list is empty
func
(
api
*
PrivateLightServerAPI
)
SetClientParams
(
ids
[]
enode
.
ID
,
params
map
[
string
]
interface
{})
error
{
var
err
error
func
(
api
*
PrivateLightServerAPI
)
SetClientParams
(
nodes
[]
string
,
params
map
[
string
]
interface
{})
error
{
var
(
ids
[]
enode
.
ID
err
error
)
for
_
,
node
:=
range
nodes
{
if
id
,
err
:=
parseNode
(
node
);
err
!=
nil
{
return
err
}
else
{
ids
=
append
(
ids
,
id
)
}
}
api
.
server
.
clientPool
.
forClients
(
ids
,
func
(
client
*
clientInfo
)
{
if
client
.
connected
{
posFactors
,
negFactors
:=
client
.
balance
.
GetPriceFactors
()
...
...
@@ -201,7 +230,11 @@ func (api *PrivateLightServerAPI) SetConnectedBias(bias time.Duration) error {
// AddBalance adds the given amount to the balance of a client if possible and returns
// the balance before and after the operation
func
(
api
*
PrivateLightServerAPI
)
AddBalance
(
id
enode
.
ID
,
amount
int64
)
(
balance
[
2
]
uint64
,
err
error
)
{
func
(
api
*
PrivateLightServerAPI
)
AddBalance
(
node
string
,
amount
int64
)
(
balance
[
2
]
uint64
,
err
error
)
{
var
id
enode
.
ID
if
id
,
err
=
parseNode
(
node
);
err
!=
nil
{
return
}
api
.
server
.
clientPool
.
forClients
([]
enode
.
ID
{
id
},
func
(
c
*
clientInfo
)
{
balance
[
0
],
balance
[
1
],
err
=
c
.
balance
.
AddBalance
(
amount
)
})
...
...
@@ -297,8 +330,14 @@ func NewPrivateDebugAPI(server *LesServer) *PrivateDebugAPI {
}
// FreezeClient forces a temporary client freeze which normally happens when the server is overloaded
func
(
api
*
PrivateDebugAPI
)
FreezeClient
(
id
enode
.
ID
)
error
{
var
err
error
func
(
api
*
PrivateDebugAPI
)
FreezeClient
(
node
string
)
error
{
var
(
id
enode
.
ID
err
error
)
if
id
,
err
=
parseNode
(
node
);
err
!=
nil
{
return
err
}
api
.
server
.
clientPool
.
forClients
([]
enode
.
ID
{
id
},
func
(
c
*
clientInfo
)
{
if
c
.
connected
{
c
.
peer
.
freeze
()
...
...
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