mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
Linter errors fixes
This commit is contained in:
parent
432b87e602
commit
ae954bad35
4 changed files with 33 additions and 22 deletions
|
@ -1,14 +1,12 @@
|
||||||
package admin
|
package admin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type AddPeersRequest struct {
|
type AddPeersRequest struct {
|
||||||
Uri string `json:"uri"`
|
Uri string `json:"uri"`
|
||||||
Intf string `json:"intf"`
|
Intf string `json:"intf"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AddPeersResponse struct {
|
type AddPeersResponse struct {
|
||||||
|
@ -17,12 +15,12 @@ type AddPeersResponse struct {
|
||||||
|
|
||||||
func (a *AdminSocket) addPeersHandler(req *AddPeersRequest, res *AddPeersResponse) error {
|
func (a *AdminSocket) addPeersHandler(req *AddPeersRequest, res *AddPeersResponse) error {
|
||||||
// Set sane defaults
|
// Set sane defaults
|
||||||
err:=a.core.AddPeer(req.Uri, req.Intf)
|
err := a.core.AddPeer(req.Uri, req.Intf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("adding peer error %s", err)
|
fmt.Printf("adding peer error %s\n", err)
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("added peer %s", req.Uri)
|
fmt.Printf("added peer %s\n", req.Uri)
|
||||||
res.List = append(res.List, req.Uri)
|
res.List = append(res.List, req.Uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -255,7 +255,7 @@ func (a *AdminSocket) StartHttpServer(nc *config.NodeConfig) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), 503)
|
http.Error(w, err.Error(), 503)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, string(b[:]))
|
fmt.Fprint(w, string(b[:]))
|
||||||
})
|
})
|
||||||
http.HandleFunc("/api/getpeers", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/api/getpeers", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Add("Content-Type", "application/json")
|
w.Header().Add("Content-Type", "application/json")
|
||||||
|
@ -269,7 +269,7 @@ func (a *AdminSocket) StartHttpServer(nc *config.NodeConfig) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), 503)
|
http.Error(w, err.Error(), 503)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, string(b[:]))
|
fmt.Fprint(w, string(b[:]))
|
||||||
})
|
})
|
||||||
var docFs = ""
|
var docFs = ""
|
||||||
pakReader, err := zip.OpenReader(nc.WwwRoot)
|
pakReader, err := zip.OpenReader(nc.WwwRoot)
|
||||||
|
|
|
@ -49,12 +49,14 @@ func (l *linkMPATH) dial(url *url.URL, options linkOptions, sintf string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *linkMPATH) listen(url *url.URL, sintf string) (*Listener, error) {
|
func (l *linkMPATH) listen(url *url.URL, sintf string) (*Listener, error) {
|
||||||
hostport := url.Host
|
/*
|
||||||
if sintf != "" {
|
hostport := url.Host
|
||||||
if host, port, err := net.SplitHostPort(hostport); err == nil {
|
if sintf != "" {
|
||||||
hostport = fmt.Sprintf("[%s%%%s]:%s", host, sintf, port)
|
if host, port, err := net.SplitHostPort(hostport); err == nil {
|
||||||
|
hostport = fmt.Sprintf("[%s%%%s]:%s", host, sintf, port)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
*/
|
||||||
_, cancel := context.WithCancel(l.core.ctx)
|
_, cancel := context.WithCancel(l.core.ctx)
|
||||||
listener, err := l.listenFor(url, sintf)
|
listener, err := l.listenFor(url, sintf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -55,6 +55,9 @@ func (l *linkSCTP) dial(url *url.URL, options linkOptions, sintf string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = conn.(*sctp.SCTPConn).Connect(raddress)
|
err = conn.(*sctp.SCTPConn).Connect(raddress)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
//conn.(*sctp.SCTPConn).SetWriteBuffer(324288)
|
//conn.(*sctp.SCTPConn).SetWriteBuffer(324288)
|
||||||
//conn.(*sctp.SCTPConn).SetReadBuffer(324288)
|
//conn.(*sctp.SCTPConn).SetReadBuffer(324288)
|
||||||
//wbuf, _ := conn.(*sctp.SCTPConn).GetWriteBuffer()
|
//wbuf, _ := conn.(*sctp.SCTPConn).GetWriteBuffer()
|
||||||
|
@ -62,7 +65,10 @@ func (l *linkSCTP) dial(url *url.URL, options linkOptions, sintf string) error {
|
||||||
|
|
||||||
//l.core.log.Printf("Read buffer %d", rbuf)
|
//l.core.log.Printf("Read buffer %d", rbuf)
|
||||||
//l.core.log.Printf("Write buffer %d", wbuf)
|
//l.core.log.Printf("Write buffer %d", wbuf)
|
||||||
conn.(*sctp.SCTPConn).SetEvents(sctp.SCTP_EVENT_DATA_IO)
|
err = conn.(*sctp.SCTPConn).SetEvents(sctp.SCTP_EVENT_DATA_IO)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
dial := &linkDial{
|
dial := &linkDial{
|
||||||
url: url,
|
url: url,
|
||||||
sintf: sintf,
|
sintf: sintf,
|
||||||
|
@ -72,12 +78,14 @@ func (l *linkSCTP) dial(url *url.URL, options linkOptions, sintf string) error {
|
||||||
|
|
||||||
func (l *linkSCTP) listen(url *url.URL, sintf string) (*Listener, error) {
|
func (l *linkSCTP) listen(url *url.URL, sintf string) (*Listener, error) {
|
||||||
//_, cancel := context.WithCancel(l.core.ctx)
|
//_, cancel := context.WithCancel(l.core.ctx)
|
||||||
hostport := url.Host
|
/*
|
||||||
if sintf != "" {
|
hostport := url.Host
|
||||||
if host, port, err := net.SplitHostPort(hostport); err == nil {
|
if sintf != "" {
|
||||||
hostport = fmt.Sprintf("[%s%%%s]:%s", host, sintf, port)
|
if host, port, err := net.SplitHostPort(hostport); err == nil {
|
||||||
|
hostport = fmt.Sprintf("[%s%%%s]:%s", host, sintf, port)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
*/
|
||||||
addr := l.getAddress(url.Host)
|
addr := l.getAddress(url.Host)
|
||||||
listener, err := sctp.NewSCTPListener(addr, sctp.InitMsg{NumOstreams: 2, MaxInstreams: 2, MaxAttempts: 2, MaxInitTimeout: 5}, sctp.OneToOne, false)
|
listener, err := sctp.NewSCTPListener(addr, sctp.InitMsg{NumOstreams: 2, MaxInstreams: 2, MaxAttempts: 2, MaxInitTimeout: 5}, sctp.OneToOne, false)
|
||||||
|
|
||||||
|
@ -85,7 +93,10 @@ func (l *linkSCTP) listen(url *url.URL, sintf string) (*Listener, error) {
|
||||||
//cancel()
|
//cancel()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
listener.SetEvents(sctp.SCTP_EVENT_DATA_IO)
|
err = listener.SetEvents(sctp.SCTP_EVENT_DATA_IO)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
entry := &Listener{
|
entry := &Listener{
|
||||||
Listener: listener,
|
Listener: listener,
|
||||||
closed: make(chan struct{}),
|
closed: make(chan struct{}),
|
||||||
|
@ -155,7 +166,7 @@ func (l *linkSCTP) getAddr() *net.TCPAddr {
|
||||||
return addr
|
return addr
|
||||||
}
|
}
|
||||||
|
|
||||||
//SCTP infrastructure
|
// SCTP infrastructure
|
||||||
func (l *linkSCTP) getAddress(host string) *sctp.SCTPAddr {
|
func (l *linkSCTP) getAddress(host string) *sctp.SCTPAddr {
|
||||||
|
|
||||||
//sctp supports multihoming but current implementation reuires only one path
|
//sctp supports multihoming but current implementation reuires only one path
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue