1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-22 11:30:31 +08:00

完善路由表

This commit is contained in:
fumiama
2021-12-28 15:47:21 +08:00
parent a9abad93d3
commit c707e4d90a
7 changed files with 71 additions and 14 deletions

View File

@@ -1,6 +1,11 @@
package link
import "github.com/fumiama/WireGold/gold/head"
import (
"encoding/json"
"errors"
"github.com/fumiama/WireGold/gold/head"
)
// 收到询问包的处理函数
func (l *Link) onQuery(packet *head.Packet) {
@@ -12,3 +17,16 @@ func (l *Link) onQuery(packet *head.Packet) {
// ---- 封装 Notify 到 新的 packet.Data
// ---- 调用 l.Send 发送到对方
}
// SendQuery 主动发起查询,询问对方是否可以到达 peers
func (l *Link) SendQuery(peers ...string) error {
if len(peers) == 0 {
return errors.New("len(peers) is 0")
}
data, err := json.Marshal(peers)
if err != nil {
return err
}
_, err = l.Write(head.NewPacket(head.ProtoQuery, 0, 0, data))
return err
}