mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
Metadata exchange without sessions
This commit is contained in:
parent
affddfb2fe
commit
d5031a5cb6
6 changed files with 187 additions and 113 deletions
|
@ -322,6 +322,14 @@ func (a *admin) init(c *Core, listenaddr string) {
|
|||
return admin_info{}, err
|
||||
}
|
||||
})
|
||||
a.addHandler("getMeta", []string{"box_pub_key", "coords"}, func(in admin_info) (admin_info, error) {
|
||||
result, err := a.admin_getMeta(in["box_pub_key"].(string), in["coords"].(string))
|
||||
if err == nil {
|
||||
return admin_info{"metadata": string(result)}, nil
|
||||
} else {
|
||||
return admin_info{}, err
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// start runs the admin API socket to listen for / respond to admin API calls.
|
||||
|
@ -806,6 +814,50 @@ func (a *admin) admin_dhtPing(keyString, coordString, targetString string) (dhtR
|
|||
return dhtRes{}, errors.New(fmt.Sprintf("DHT ping timeout: %s", keyString))
|
||||
}
|
||||
|
||||
func (a *admin) admin_getMeta(keyString, coordString string) (metadataPayload, error) {
|
||||
var key boxPubKey
|
||||
if keyBytes, err := hex.DecodeString(keyString); err != nil {
|
||||
return metadataPayload{}, err
|
||||
} else {
|
||||
copy(key[:], keyBytes)
|
||||
}
|
||||
var coords []byte
|
||||
for _, cstr := range strings.Split(strings.Trim(coordString, "[]"), " ") {
|
||||
if cstr == "" {
|
||||
// Special case, happens if trimmed is the empty string, e.g. this is the root
|
||||
continue
|
||||
}
|
||||
if u64, err := strconv.ParseUint(cstr, 10, 8); err != nil {
|
||||
return metadataPayload{}, err
|
||||
} else {
|
||||
coords = append(coords, uint8(u64))
|
||||
}
|
||||
}
|
||||
response := make(chan *metadataPayload, 1)
|
||||
sendMetaRequest := func() {
|
||||
a.core.metadata.callbacks[key] = metadataCallback{
|
||||
created: time.Now(),
|
||||
call: func(meta *metadataPayload) {
|
||||
defer func() { recover() }()
|
||||
select {
|
||||
case response <- meta:
|
||||
default:
|
||||
}
|
||||
},
|
||||
}
|
||||
a.core.metadata.sendMetadata(key, coords, false)
|
||||
}
|
||||
a.core.router.doAdmin(sendMetaRequest)
|
||||
go func() {
|
||||
time.Sleep(6 * time.Second)
|
||||
close(response)
|
||||
}()
|
||||
for res := range response {
|
||||
return *res, nil
|
||||
}
|
||||
return metadataPayload{}, errors.New(fmt.Sprintf("getMeta timeout: %s", keyString))
|
||||
}
|
||||
|
||||
// getResponse_dot returns a response for a graphviz dot formatted representation of the known parts of the network.
|
||||
// This is color-coded and labeled, and includes the self node, switch peers, nodes known to the DHT, and nodes with open sessions.
|
||||
// The graph is structured as a tree with directed links leading away from the root.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue