Reimplement AddPeer and RemovePeer for admin socket (#951)

* Reimplement AddPeer and RemovePeer for admin socket

Fix #950

* Disconnect the peer on `removePeer`

Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
This commit is contained in:
ehmry 2022-10-02 06:35:43 -05:00 committed by GitHub
parent c922eba2d8
commit 7db934488e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 97 additions and 73 deletions

View file

@ -108,10 +108,10 @@ func (l *links) isConnectedTo(info linkInfo) bool {
return isConnected
}
func (l *links) call(u *url.URL, sintf string) error {
func (l *links) call(u *url.URL, sintf string) (linkInfo, error) {
info := linkInfoFor(u.Scheme, sintf, u.Host)
if l.isConnectedTo(info) {
return nil
return info, nil
}
options := linkOptions{
pinnedEd25519Keys: map[keyArray]struct{}{},
@ -119,7 +119,7 @@ func (l *links) call(u *url.URL, sintf string) error {
for _, pubkey := range u.Query()["key"] {
sigPub, err := hex.DecodeString(pubkey)
if err != nil {
return fmt.Errorf("pinned key contains invalid hex characters")
return info, fmt.Errorf("pinned key contains invalid hex characters")
}
var sigPubKey keyArray
copy(sigPubKey[:], sigPub)
@ -172,9 +172,9 @@ func (l *links) call(u *url.URL, sintf string) error {
}()
default:
return errors.New("unknown call scheme: " + u.Scheme)
return info, errors.New("unknown call scheme: " + u.Scheme)
}
return nil
return info, nil
}
func (l *links) listen(u *url.URL, sintf string) (*Listener, error) {