Release v0.3.0

This commit is contained in:
Manu Herrera
2020-11-09 10:05:29 -03:00
parent 4e9aa7a3c5
commit 8107c4478b
1265 changed files with 440488 additions and 107809 deletions

19
vendor/github.com/lightningnetwork/lnd/clock/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,19 @@
Copyright (C) 2015-2018 Lightning Labs and The Lightning Network Developers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,24 @@
package clock
import (
"time"
)
// DefaultClock implements Clock interface by simply calling the appropriate
// time functions.
type DefaultClock struct{}
// NewDefaultClock constructs a new DefaultClock.
func NewDefaultClock() Clock {
return &DefaultClock{}
}
// Now simply returns time.Now().
func (DefaultClock) Now() time.Time {
return time.Now()
}
// TickAfter simply wraps time.After().
func (DefaultClock) TickAfter(duration time.Duration) <-chan time.Time {
return time.After(duration)
}

3
vendor/github.com/lightningnetwork/lnd/clock/go.mod generated vendored Normal file
View File

@@ -0,0 +1,3 @@
module github.com/lightningnetwork/lnd/clock
go 1.13

View File

@@ -0,0 +1,16 @@
package clock
import (
"time"
)
// Clock is an interface that provides a time functions for LND packages.
// This is useful during testing when a concrete time reference is needed.
type Clock interface {
// Now returns the current local time (as defined by the Clock).
Now() time.Time
// TickAfter returns a channel that will receive a tick after the specified
// duration has passed.
TickAfter(duration time.Duration) <-chan time.Time
}

View File

@@ -0,0 +1,96 @@
package clock
import (
"sync"
"time"
)
// TestClock can be used in tests to mock time.
type TestClock struct {
currentTime time.Time
timeChanMap map[time.Time][]chan time.Time
timeLock sync.Mutex
tickSignal chan time.Duration
}
// NewTestClock returns a new test clock.
func NewTestClock(startTime time.Time) *TestClock {
return &TestClock{
currentTime: startTime,
timeChanMap: make(map[time.Time][]chan time.Time),
}
}
// NewTestClockWithTickSignal will create a new test clock with an added
// channel which will be used to signal when a new ticker is registered.
// This is useful when creating a ticker on a separate goroutine and we'd
// like to wait for that to happen before advancing the test case.
func NewTestClockWithTickSignal(startTime time.Time,
tickSignal chan time.Duration) *TestClock {
testClock := NewTestClock(startTime)
testClock.tickSignal = tickSignal
return testClock
}
// Now returns the current (test) time.
func (c *TestClock) Now() time.Time {
c.timeLock.Lock()
defer c.timeLock.Unlock()
return c.currentTime
}
// TickAfter returns a channel that will receive a tick after the specified
// duration has passed passed by the user set test time.
func (c *TestClock) TickAfter(duration time.Duration) <-chan time.Time {
c.timeLock.Lock()
defer func() {
c.timeLock.Unlock()
// Signal that the ticker has been added.
if c.tickSignal != nil {
c.tickSignal <- duration
}
}()
triggerTime := c.currentTime.Add(duration)
ch := make(chan time.Time, 1)
// If already expired, tick immediately.
if !triggerTime.After(c.currentTime) {
ch <- c.currentTime
return ch
}
// Otherwise store the channel until the trigger time is there.
chans := c.timeChanMap[triggerTime]
chans = append(chans, ch)
c.timeChanMap[triggerTime] = chans
return ch
}
// SetTime sets the (test) time and triggers tick channels when they expire.
func (c *TestClock) SetTime(now time.Time) {
c.timeLock.Lock()
defer c.timeLock.Unlock()
c.currentTime = now
remainingChans := make(map[time.Time][]chan time.Time)
for triggerTime, chans := range c.timeChanMap {
// If the trigger time is still in the future, keep this channel
// in the channel map for later.
if triggerTime.After(now) {
remainingChans[triggerTime] = chans
continue
}
for _, c := range chans {
c <- now
}
}
c.timeChanMap = remainingChans
}