mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-23 10:05:17 +00:00
cleanup unused code
This commit is contained in:
parent
180654c495
commit
e25ad9ed21
@ -69,10 +69,6 @@ func (l *links) init(c *Core) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *links) reconfigure() {
|
||||
l.tcp.reconfigure()
|
||||
}
|
||||
|
||||
func (l *links) call(u *url.URL, sintf string) error {
|
||||
//u, err := url.Parse(uri)
|
||||
//if err != nil {
|
||||
|
@ -130,46 +130,6 @@ func (t *tcp) stop() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *tcp) reconfigure() {
|
||||
panic("TODO cleanup obsolete reconfigure() stuff")
|
||||
/*
|
||||
t.links.core.config.Mutex.RLock()
|
||||
added := util.Difference(t.links.core.config.Current.Listen, t.links.core.config.Previous.Listen)
|
||||
deleted := util.Difference(t.links.core.config.Previous.Listen, t.links.core.config.Current.Listen)
|
||||
t.links.core.config.Mutex.RUnlock()
|
||||
if len(added) > 0 || len(deleted) > 0 {
|
||||
for _, a := range added {
|
||||
switch a[:6] {
|
||||
case "tcp://":
|
||||
if _, err := t.listen(a[6:], nil); err != nil {
|
||||
t.links.core.log.Errorln("Error adding TCP", a[6:], "listener:", err)
|
||||
}
|
||||
case "tls://":
|
||||
if _, err := t.listen(a[6:], t.tls.forListener); err != nil {
|
||||
t.links.core.log.Errorln("Error adding TLS", a[6:], "listener:", err)
|
||||
}
|
||||
default:
|
||||
t.links.core.log.Errorln("Failed to add listener: listener", a, "is not correctly formatted, ignoring")
|
||||
}
|
||||
}
|
||||
for _, d := range deleted {
|
||||
if d[:6] != "tcp://" && d[:6] != "tls://" {
|
||||
t.links.core.log.Errorln("Failed to delete listener: listener", d, "is not correctly formatted, ignoring")
|
||||
continue
|
||||
}
|
||||
t.mutex.Lock()
|
||||
if listener, ok := t.listeners[d[6:]]; ok {
|
||||
t.mutex.Unlock()
|
||||
listener.Stop()
|
||||
t.links.core.log.Infoln("Stopped TCP listener:", d[6:])
|
||||
} else {
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
func (t *tcp) listenURL(u *url.URL, sintf string) (*TcpListener, error) {
|
||||
var listener *TcpListener
|
||||
var err error
|
||||
|
@ -27,23 +27,11 @@ type nodeinfo struct {
|
||||
callbacks map[keyArray]nodeinfoCallback
|
||||
}
|
||||
|
||||
type nodeinfoCached struct {
|
||||
payload NodeInfoPayload
|
||||
created time.Time
|
||||
}
|
||||
|
||||
type nodeinfoCallback struct {
|
||||
call func(nodeinfo NodeInfoPayload)
|
||||
created time.Time
|
||||
}
|
||||
|
||||
// Represents a session nodeinfo packet.
|
||||
type nodeinfoReqRes struct {
|
||||
Key keyArray // Sender's permanent key
|
||||
IsResponse bool
|
||||
NodeInfo NodeInfoPayload
|
||||
}
|
||||
|
||||
// Initialises the nodeinfo cache/callback maps, and starts a goroutine to keep
|
||||
// the cache/callback maps clean of stale entries
|
||||
func (m *nodeinfo) init(proto *protoHandler) {
|
||||
@ -69,13 +57,6 @@ func (m *nodeinfo) _cleanup() {
|
||||
})
|
||||
}
|
||||
|
||||
// Add a callback for a nodeinfo lookup
|
||||
func (m *nodeinfo) addCallback(sender keyArray, call func(nodeinfo NodeInfoPayload)) {
|
||||
m.Act(nil, func() {
|
||||
m._addCallback(sender, call)
|
||||
})
|
||||
}
|
||||
|
||||
func (m *nodeinfo) _addCallback(sender keyArray, call func(nodeinfo NodeInfoPayload)) {
|
||||
m.callbacks[sender] = nodeinfoCallback{
|
||||
created: time.Now(),
|
||||
@ -91,14 +72,6 @@ func (m *nodeinfo) _callback(sender keyArray, nodeinfo NodeInfoPayload) {
|
||||
}
|
||||
}
|
||||
|
||||
// Get the current node's nodeinfo
|
||||
func (m *nodeinfo) getNodeInfo() (p NodeInfoPayload) {
|
||||
phony.Block(m, func() {
|
||||
p = m._getNodeInfo()
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (m *nodeinfo) _getNodeInfo() NodeInfoPayload {
|
||||
return m.myNodeInfo
|
||||
}
|
||||
|
@ -61,12 +61,6 @@ func (p *protoHandler) handleProto(from phony.Actor, key keyArray, bs []byte) {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *protoHandler) handleDebug(from phony.Actor, key keyArray, bs []byte) {
|
||||
p.Act(from, func() {
|
||||
p._handleDebug(key, bs)
|
||||
})
|
||||
}
|
||||
|
||||
func (p *protoHandler) _handleDebug(key keyArray, bs []byte) {
|
||||
if len(bs) == 0 {
|
||||
return
|
||||
|
@ -1,103 +0,0 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"runtime"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Cancellation is used to signal when things should shut down, such as signaling anything associated with a Conn to exit.
|
||||
// This is and is similar to a context, but with an error to specify the reason for the cancellation.
|
||||
type Cancellation interface {
|
||||
Finished() <-chan struct{} // Finished returns a channel which will be closed when Cancellation.Cancel is first called.
|
||||
Cancel(error) error // Cancel closes the channel returned by Finished and sets the error returned by error, or else returns the existing error if the Cancellation has already run.
|
||||
Error() error // Error returns the error provided to Cancel, or nil if no error has been provided.
|
||||
}
|
||||
|
||||
// CancellationFinalized is an error returned if a cancellation object was garbage collected and the finalizer was run.
|
||||
// If you ever see this, then you're probably doing something wrong with your code.
|
||||
var CancellationFinalized = errors.New("finalizer called")
|
||||
|
||||
// CancellationTimeoutError is used when a CancellationWithTimeout or CancellationWithDeadline is cancelled due to said timeout.
|
||||
var CancellationTimeoutError = errors.New("timeout")
|
||||
|
||||
// CancellationFinalizer is set as a finalizer when creating a new cancellation with NewCancellation(), and generally shouldn't be needed by the user, but is included in case other implementations of the same interface want to make use of it.
|
||||
func CancellationFinalizer(c Cancellation) {
|
||||
c.Cancel(CancellationFinalized)
|
||||
}
|
||||
|
||||
type cancellation struct {
|
||||
cancel chan struct{}
|
||||
mutex sync.RWMutex
|
||||
err error
|
||||
done bool
|
||||
}
|
||||
|
||||
// NewCancellation returns a pointer to a struct satisfying the Cancellation interface.
|
||||
func NewCancellation() Cancellation {
|
||||
c := cancellation{
|
||||
cancel: make(chan struct{}),
|
||||
}
|
||||
runtime.SetFinalizer(&c, CancellationFinalizer)
|
||||
return &c
|
||||
}
|
||||
|
||||
// Finished returns a channel which will be closed when Cancellation.Cancel is first called.
|
||||
func (c *cancellation) Finished() <-chan struct{} {
|
||||
return c.cancel
|
||||
}
|
||||
|
||||
// Cancel closes the channel returned by Finished and sets the error returned by error, or else returns the existing error if the Cancellation has already run.
|
||||
func (c *cancellation) Cancel(err error) error {
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
if c.done {
|
||||
return c.err
|
||||
}
|
||||
c.err = err
|
||||
c.done = true
|
||||
close(c.cancel)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Error returns the error provided to Cancel, or nil if no error has been provided.
|
||||
func (c *cancellation) Error() error {
|
||||
c.mutex.RLock()
|
||||
err := c.err
|
||||
c.mutex.RUnlock()
|
||||
return err
|
||||
}
|
||||
|
||||
// CancellationChild returns a new Cancellation which can be Cancelled independently of the parent, but which will also be Cancelled if the parent is Cancelled first.
|
||||
func CancellationChild(parent Cancellation) Cancellation {
|
||||
child := NewCancellation()
|
||||
go func() {
|
||||
select {
|
||||
case <-child.Finished():
|
||||
case <-parent.Finished():
|
||||
child.Cancel(parent.Error())
|
||||
}
|
||||
}()
|
||||
return child
|
||||
}
|
||||
|
||||
// CancellationWithTimeout returns a ChildCancellation that will automatically be Cancelled with a CancellationTimeoutError after the timeout.
|
||||
func CancellationWithTimeout(parent Cancellation, timeout time.Duration) Cancellation {
|
||||
child := CancellationChild(parent)
|
||||
go func() {
|
||||
timer := time.NewTimer(timeout)
|
||||
defer TimerStop(timer)
|
||||
select {
|
||||
case <-child.Finished():
|
||||
case <-timer.C:
|
||||
child.Cancel(CancellationTimeoutError)
|
||||
}
|
||||
}()
|
||||
return child
|
||||
}
|
||||
|
||||
// CancellationWithTimeout returns a ChildCancellation that will automatically be Cancelled with a CancellationTimeoutError after the specified deadline.
|
||||
func CancellationWithDeadline(parent Cancellation, deadline time.Time) Cancellation {
|
||||
return CancellationWithTimeout(parent, deadline.Sub(time.Now()))
|
||||
}
|
Loading…
Reference in New Issue
Block a user