mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-30 07:05:06 +03:00
Merge branch 'develop' of https://github.com/yggdrasil-network/yggdrasil-go into yggdrasil-v0.4.7-develop
This commit is contained in:
commit
35cc180647
20 changed files with 309 additions and 178 deletions
|
@ -6,8 +6,8 @@ package core
|
|||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"io"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
@ -51,9 +51,12 @@ func (l *links) init(c *Core) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (l *links) call(u *url.URL, sintf string) (linkInfo, error) {
|
||||
info := linkInfoFor(u.Scheme, sintf, u.Host)
|
||||
func (l *links) call(u *url.URL, sintf string, errch chan<- error) (info linkInfo, err error) {
|
||||
info = linkInfoFor(u.Scheme, sintf, u.Host)
|
||||
if l.isConnectedTo(info) {
|
||||
if errch != nil {
|
||||
close(errch) // already connected, no error
|
||||
}
|
||||
return info, nil
|
||||
}
|
||||
options := linkOptions{
|
||||
|
@ -62,6 +65,9 @@ func (l *links) call(u *url.URL, sintf string) (linkInfo, error) {
|
|||
for _, pubkey := range u.Query()["key"] {
|
||||
sigPub, err := hex.DecodeString(pubkey)
|
||||
if err != nil {
|
||||
if errch != nil {
|
||||
close(errch)
|
||||
}
|
||||
return info, fmt.Errorf("pinned key contains invalid hex characters")
|
||||
}
|
||||
var sigPubKey keyArray
|
||||
|
@ -71,6 +77,9 @@ func (l *links) call(u *url.URL, sintf string) (linkInfo, error) {
|
|||
if p := u.Query().Get("priority"); p != "" {
|
||||
pi, err := strconv.ParseUint(p, 10, 8)
|
||||
if err != nil {
|
||||
if errch != nil {
|
||||
close(errch)
|
||||
}
|
||||
return info, fmt.Errorf("priority invalid: %w", err)
|
||||
}
|
||||
options.priority = uint8(pi)
|
||||
|
@ -78,15 +87,27 @@ func (l *links) call(u *url.URL, sintf string) (linkInfo, error) {
|
|||
switch info.linkType {
|
||||
case "tcp":
|
||||
go func() {
|
||||
if errch != nil {
|
||||
defer close(errch)
|
||||
}
|
||||
if err := l.tcp.dial(u, options, sintf); err != nil && err != io.EOF {
|
||||
l.core.log.Warnf("Failed to dial TCP %s: %s\n", u.Host, err)
|
||||
if errch != nil {
|
||||
errch <- err
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
case "socks":
|
||||
go func() {
|
||||
if errch != nil {
|
||||
defer close(errch)
|
||||
}
|
||||
if err := l.socks.dial(u, options); err != nil && err != io.EOF {
|
||||
l.core.log.Warnf("Failed to dial SOCKS %s: %s\n", u.Host, err)
|
||||
if errch != nil {
|
||||
errch <- err
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -109,30 +130,57 @@ func (l *links) call(u *url.URL, sintf string) (linkInfo, error) {
|
|||
}
|
||||
}
|
||||
go func() {
|
||||
if errch != nil {
|
||||
defer close(errch)
|
||||
}
|
||||
if err := l.tls.dial(u, options, sintf, tlsSNI); err != nil && err != io.EOF {
|
||||
l.core.log.Warnf("Failed to dial TLS %s: %s\n", u.Host, err)
|
||||
if errch != nil {
|
||||
errch <- err
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
case "unix":
|
||||
go func() {
|
||||
if errch != nil {
|
||||
defer close(errch)
|
||||
}
|
||||
if err := l.unix.dial(u, options, sintf); err != nil && err != io.EOF {
|
||||
l.core.log.Warnf("Failed to dial UNIX %s: %s\n", u.Host, err)
|
||||
if errch != nil {
|
||||
errch <- err
|
||||
}
|
||||
}
|
||||
}()
|
||||
case "sctp":
|
||||
go func() {
|
||||
case "sctp":
|
||||
go func() {
|
||||
if errch != nil {
|
||||
defer close(errch)
|
||||
}
|
||||
if err := l.sctp.dial(u, options, sintf); err != nil && err != io.EOF {
|
||||
l.core.log.Warnf("Failed to dial SCTP %s: %s\n", u.Host, err)
|
||||
}
|
||||
}()
|
||||
l.core.log.Warnf("Failed to dial SCTP %s: %s\n", u.Host, err)
|
||||
if errch != nil {
|
||||
errch <- err
|
||||
}
|
||||
}
|
||||
}()
|
||||
case "mpath":
|
||||
go func() {
|
||||
if errch != nil {
|
||||
defer close(errch)
|
||||
}
|
||||
if err := l.mpath.dial(u, options, sintf); err != nil && err != io.EOF {
|
||||
l.core.log.Warnf("Failed to dial MPATH %s: %s\n", u.Host, err)
|
||||
if errch != nil {
|
||||
errch <- err
|
||||
}
|
||||
}
|
||||
}()
|
||||
default:
|
||||
if errch != nil {
|
||||
close(errch)
|
||||
}
|
||||
return info, errors.New("unknown call scheme: " + u.Scheme)
|
||||
}
|
||||
return info, nil
|
||||
|
@ -148,8 +196,8 @@ func (l *links) listen(u *url.URL, sintf string) (*Listener, error) {
|
|||
listener, err = l.tls.listen(u, sintf)
|
||||
case "unix":
|
||||
listener, err = l.unix.listen(u, sintf)
|
||||
case "sctp":
|
||||
listener, err = l.sctp.listen(u, sintf)
|
||||
case "sctp":
|
||||
listener, err = l.sctp.listen(u, sintf)
|
||||
case "mpath":
|
||||
listener, err = l.mpath.listen(u, sintf)
|
||||
default:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue