Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nodemanager
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Odysseus
nodemanager
Commits
1a2c0501
Commit
1a2c0501
authored
Mar 25, 2024
by
vicotor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update worker register info
parent
ac466097
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
13 deletions
+44
-13
workerManager.go
server/workerManager.go
+2
-2
worker_registry.go
server/worker_registry.go
+12
-0
crypto_test.go
utils/crypto_test.go
+30
-11
No files found.
server/workerManager.go
View file @
1a2c0501
...
...
@@ -66,7 +66,7 @@ type Worker struct {
info
workerInfo
workerAddr
string
// worker address from public-key
deviceInfoHash
[]
byte
recentTask
*
lru
.
Cache
recentTask
*
lru
.
ARC
Cache
status
string
stream
omanager
.
NodeManagerService_RegisterWorkerServer
...
...
@@ -195,7 +195,7 @@ func (wm *WorkerManager) AddNewWorker(id int64, worker omanager.NodeManagerServi
stream
:
worker
,
}
taskCache
,
err
:=
lru
.
New
(
100
)
taskCache
,
err
:=
lru
.
New
ARC
(
100
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
server/worker_registry.go
View file @
1a2c0501
...
...
@@ -37,8 +37,20 @@ func (w workerRegistry) DetailInfo() (json.RawMessage, error) {
return
nil
,
fmt
.
Errorf
(
"worker address is empty"
)
}
taskList
:=
make
([]
string
,
0
)
keys
:=
w
.
worker
.
recentTask
.
Keys
()
for
_
,
key
:=
range
keys
{
if
d
,
exist
:=
w
.
worker
.
recentTask
.
Get
(
key
);
exist
{
dtask
:=
d
.
(
*
dispatchTask
)
if
dtask
.
status
<
TASK_FINISHED
{
taskList
=
append
(
taskList
,
key
.
(
string
))
}
}
}
info
:=
query
.
WorkerInfo
{
ActiveNM
:
make
([]
string
,
0
),
TaskList
:
taskList
,
}
if
w
.
worker
.
info
.
nodeInfo
!=
nil
{
info
.
BenefitAddress
=
w
.
worker
.
info
.
nodeInfo
.
BenefitAddress
...
...
utils/crypto_test.go
View file @
1a2c0501
package
utils
import
(
"encoding/hex"
"fmt"
"github.com/ethereum/go-ethereum/crypto"
"github.com/
magiconair/properties/assert
"
"github.com/
odysseus/service-registry/utils
"
"testing"
)
func
TestCombineBytes
(
t
*
testing
.
T
)
{
hash
:=
FromHex
(
"0xaa81f776e43511492b9db11894c71e7fdca3f09bd24dc1fe93f1e017e6eef947"
)
pubkey
:=
FromHex
(
"0423965c5d5b4c2fa03fe024cfbcd413db25e7c420b73bd5dccb78fada9e22d4848d32952c913ae0cdcc70efa38094dc49c05c6a0cec7e1712557050da7d7bd05a"
)
signature
:=
FromHex
(
"db2be765e420d3b67e695612a349090e9fe2446c6b7875d36a0e6268bc3619e14d24b93a5d8f7f55b9649ad3f5a636a886c480fbe6fb5c49f3b716c0ea66ea7a01"
)
if
len
(
signature
)
==
65
{
signature
=
signature
[
:
64
]
}
if
len
(
pubkey
)
>
65
{
pubkey
=
pubkey
[
:
65
]
id
:=
"9effda2d-f3ae-48e0-a54e-e88e84c6b804"
idData
:=
[]
byte
(
id
)
reqHash
:=
"7c180aec90bf54c27988885fd1c5d2e7d48b2db50e871f24e55f6f4a2f6b1380"
redData
,
_
:=
hex
.
DecodeString
(
reqHash
)
datahash
:=
"4b42042af97e612aafd03b2ac7e57be39118dece1f1333f6db364aaf944fcd9d"
data
,
_
:=
hex
.
DecodeString
(
datahash
)
signanture
:=
"78006ed3cef7b2d15c47b53958fdc305ed1fda3bd4e4638a9033aeb52c9837b524f69e922da7844f557b7be4757ee8c355ef15ba6b3e31e0fc40ed403d9f72ec00"
sigData
,
_
:=
hex
.
DecodeString
(
signanture
)
dataHash
:=
crypto
.
Keccak256Hash
(
utils
.
CombineBytes
(
idData
,
redData
,
data
))
npubkey
,
err
:=
crypto
.
SigToPub
(
dataHash
[
:
],
sigData
)
if
err
!=
nil
{
return
}
verified
:=
crypto
.
VerifySignature
(
pubkey
,
hash
,
signature
)
assert
.
Equal
(
t
,
verified
,
true
)
addr
:=
crypto
.
PubkeyToAddress
(
*
npubkey
)
fmt
.
Println
(
"addr:"
,
addr
)
//
//hash := FromHex("0xaa81f776e43511492b9db11894c71e7fdca3f09bd24dc1fe93f1e017e6eef947")
//pubkey := FromHex("0423965c5d5b4c2fa03fe024cfbcd413db25e7c420b73bd5dccb78fada9e22d4848d32952c913ae0cdcc70efa38094dc49c05c6a0cec7e1712557050da7d7bd05a")
//signature := FromHex("db2be765e420d3b67e695612a349090e9fe2446c6b7875d36a0e6268bc3619e14d24b93a5d8f7f55b9649ad3f5a636a886c480fbe6fb5c49f3b716c0ea66ea7a01")
//if len(signature) == 65 {
// signature = signature[:64]
//}
//if len(pubkey) > 65 {
// pubkey = pubkey[:65]
//}
//verified := crypto.VerifySignature(pubkey, hash, signature)
//assert.Equal(t, verified, true)
}
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