mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
update dependencies
This commit is contained in:
parent
90f1277ee5
commit
346284cbed
6 changed files with 40 additions and 67 deletions
30
Gopkg.lock
generated
30
Gopkg.lock
generated
|
@ -52,8 +52,8 @@
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/schollz/peerdiscovery"
|
name = "github.com/schollz/peerdiscovery"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "2665d149a222cb3cf607ef0cf70ce7909462c50f"
|
revision = "94ddd4cf05a8a6052e334c69ac1cd86486de10af"
|
||||||
version = "v0.1.0"
|
version = "v1.1.0"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/schollz/progressbar"
|
name = "github.com/schollz/progressbar"
|
||||||
|
@ -88,41 +88,25 @@
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
name = "github.com/yudai/hcl"
|
name = "github.com/yudai/hcl"
|
||||||
packages = [
|
packages = [".","hcl","json"]
|
||||||
".",
|
|
||||||
"hcl",
|
|
||||||
"json"
|
|
||||||
]
|
|
||||||
revision = "5fa2393b3552119bf33a69adb1402a1160cba23d"
|
revision = "5fa2393b3552119bf33a69adb1402a1160cba23d"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
name = "golang.org/x/crypto"
|
name = "golang.org/x/crypto"
|
||||||
packages = [
|
packages = ["pbkdf2","scrypt","ssh/terminal"]
|
||||||
"pbkdf2",
|
|
||||||
"scrypt",
|
|
||||||
"ssh/terminal"
|
|
||||||
]
|
|
||||||
revision = "2b6c08872f4b66da917bb4ce98df4f0307330f78"
|
revision = "2b6c08872f4b66da917bb4ce98df4f0307330f78"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
name = "golang.org/x/net"
|
name = "golang.org/x/net"
|
||||||
packages = [
|
packages = ["bpf","internal/iana","internal/socket","ipv4"]
|
||||||
"bpf",
|
|
||||||
"internal/iana",
|
|
||||||
"internal/socket",
|
|
||||||
"ipv4"
|
|
||||||
]
|
|
||||||
revision = "5f9ae10d9af5b1c89ae6904293b14b064d4ada23"
|
revision = "5f9ae10d9af5b1c89ae6904293b14b064d4ada23"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
name = "golang.org/x/sys"
|
name = "golang.org/x/sys"
|
||||||
packages = [
|
packages = ["unix","windows"]
|
||||||
"unix",
|
|
||||||
"windows"
|
|
||||||
]
|
|
||||||
revision = "79b0c6888797020a994db17c8510466c72fe75d9"
|
revision = "79b0c6888797020a994db17c8510466c72fe75d9"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
|
@ -140,6 +124,6 @@
|
||||||
[solve-meta]
|
[solve-meta]
|
||||||
analyzer-name = "dep"
|
analyzer-name = "dep"
|
||||||
analyzer-version = 1
|
analyzer-version = 1
|
||||||
inputs-digest = "4145287e28323d22a74771b8f17cc9a94d13e6297e0de995820e1bc7953948d7"
|
inputs-digest = "93fd6df35a71aeabf37bf934c95bab3e099b86f74ad0479e0ce491695a996527"
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
solver-version = 1
|
solver-version = 1
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
name = "github.com/schollz/mnemonicode"
|
name = "github.com/schollz/mnemonicode"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
version = "0.1.0"
|
version = "1.1.0"
|
||||||
name = "github.com/schollz/peerdiscovery"
|
name = "github.com/schollz/peerdiscovery"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
|
|
5
vendor/github.com/schollz/peerdiscovery/README.md
generated
vendored
5
vendor/github.com/schollz/peerdiscovery/README.md
generated
vendored
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
[](https://travis-ci.org/schollz/peerdiscovery)
|
[](https://travis-ci.org/schollz/peerdiscovery)
|
||||||
[](https://goreportcard.com/report/github.com/schollz/peerdiscovery)
|
[](https://goreportcard.com/report/github.com/schollz/peerdiscovery)
|
||||||
[](https://gocover.io/github.com/schollz/peerdiscovery)
|
[](https://gocover.io/github.com/schollz/peerdiscovery)
|
||||||
[](https://godoc.org/github.com/schollz/peerdiscovery)
|
[](https://godoc.org/github.com/schollz/peerdiscovery)
|
||||||
|
|
||||||
Pure-go library for cross-platform thread-safe local peer discovery using UDP broadcast. I needed to use peer discovery for [croc](https://github.com/schollz/croc) and everything I tried had problems, so I made another one.
|
Pure-go library for cross-platform thread-safe local peer discovery using UDP broadcast. I needed to use peer discovery for [croc](https://github.com/schollz/croc) and everything I tried had problems, so I made another one.
|
||||||
|
@ -21,8 +21,7 @@ go get -u github.com/schollz/peerdiscovery
|
||||||
The following is a code to find the first peer on the local network and print it out.
|
The following is a code to find the first peer on the local network and print it out.
|
||||||
|
|
||||||
```golang
|
```golang
|
||||||
p, _ := peerdiscovery.New(peerdiscovery.Settings{Limit: 1})
|
discoveries, _ := peerdiscovery.Discover(peerdiscovery.Settings{Limit: 1})
|
||||||
discoveries, _ := p.Discover()
|
|
||||||
for _, d := range discoveries {
|
for _, d := range discoveries {
|
||||||
fmt.Printf("discovered '%s'\n", d.Address)
|
fmt.Printf("discovered '%s'\n", d.Address)
|
||||||
}
|
}
|
||||||
|
|
7
vendor/github.com/schollz/peerdiscovery/examples/main.go
generated
vendored
7
vendor/github.com/schollz/peerdiscovery/examples/main.go
generated
vendored
|
@ -23,17 +23,14 @@ func main() {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// discover peers
|
// discover peers
|
||||||
p, err := peerdiscovery.New(peerdiscovery.Settings{
|
discoveries, err := peerdiscovery.Discover(peerdiscovery.Settings{
|
||||||
Limit: -1,
|
Limit: -1,
|
||||||
Payload: []byte(randStringBytesMaskImprSrc(10)),
|
Payload: []byte(randStringBytesMaskImprSrc(10)),
|
||||||
Delay: 500 * time.Millisecond,
|
Delay: 500 * time.Millisecond,
|
||||||
TimeLimit: 10 * time.Second,
|
TimeLimit: 10 * time.Second,
|
||||||
})
|
})
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
discoveries, err := p.Discover()
|
// print out results
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
|
|
39
vendor/github.com/schollz/peerdiscovery/peerdiscovery.go
generated
vendored
39
vendor/github.com/schollz/peerdiscovery/peerdiscovery.go
generated
vendored
|
@ -26,11 +26,12 @@ type Settings struct {
|
||||||
// Limit is the number of peers to discover, use < 1 for unlimited.
|
// Limit is the number of peers to discover, use < 1 for unlimited.
|
||||||
Limit int
|
Limit int
|
||||||
// Port is the port to broadcast on (the peers must also broadcast using the same port).
|
// Port is the port to broadcast on (the peers must also broadcast using the same port).
|
||||||
// The default port is 999.
|
// The default port is 9999.
|
||||||
Port string
|
Port string
|
||||||
// MulticastAddress specifies the multicast address.
|
// MulticastAddress specifies the multicast address.
|
||||||
// You should be able to use any between 224.0.0.0 to 239.255.255.255.
|
// You should be able to use any between 224.0.0.0 to 239.255.255.255.
|
||||||
// By default it uses the Simple Service Discovery Protocol address (239.255.255.250).
|
// By default it uses the Simple Service Discovery Protocol
|
||||||
|
// address (239.255.255.250).
|
||||||
MulticastAddress string
|
MulticastAddress string
|
||||||
// Payload is the bytes that are sent out with each broadcast. Must be short.
|
// Payload is the bytes that are sent out with each broadcast. Must be short.
|
||||||
Payload []byte
|
Payload []byte
|
||||||
|
@ -44,23 +45,25 @@ type Settings struct {
|
||||||
multicastAddressNumbers []uint8
|
multicastAddressNumbers []uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
// PeerDiscovery is the object that can do the discovery for finding LAN peers.
|
// peerDiscovery is the object that can do the discovery for finding LAN peers.
|
||||||
type PeerDiscovery struct {
|
type peerDiscovery struct {
|
||||||
settings Settings
|
settings Settings
|
||||||
|
|
||||||
received map[string][]byte
|
received map[string][]byte
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new PeerDiscovery object which can be used to discover peers.
|
// initialize returns a new peerDiscovery object which can be used to discover peers.
|
||||||
// The settings are optional. If any setting is not supplied, then defaults are used.
|
// The settings are optional. If any setting is not supplied, then defaults are used.
|
||||||
// See the Settings for more information.
|
// See the Settings for more information.
|
||||||
func New(settings ...Settings) (p *PeerDiscovery, err error) {
|
func initialize(settings Settings) (p *peerDiscovery, err error) {
|
||||||
p = new(PeerDiscovery)
|
p = new(peerDiscovery)
|
||||||
p.Lock()
|
p.Lock()
|
||||||
defer p.Unlock()
|
defer p.Unlock()
|
||||||
if len(settings) > 0 {
|
|
||||||
p.settings = settings[0]
|
// initialize settings
|
||||||
}
|
p.settings = settings
|
||||||
|
|
||||||
// defaults
|
// defaults
|
||||||
if p.settings.Port == "" {
|
if p.settings.Port == "" {
|
||||||
p.settings.Port = "9999"
|
p.settings.Port = "9999"
|
||||||
|
@ -97,7 +100,16 @@ func New(settings ...Settings) (p *PeerDiscovery, err error) {
|
||||||
// Discover will use the created settings to scan for LAN peers. It will return
|
// Discover will use the created settings to scan for LAN peers. It will return
|
||||||
// an array of the discovered peers and their associate payloads. It will not
|
// an array of the discovered peers and their associate payloads. It will not
|
||||||
// return broadcasts sent to itself.
|
// return broadcasts sent to itself.
|
||||||
func (p *PeerDiscovery) Discover() (discoveries []Discovered, err error) {
|
func Discover(settings ...Settings) (discoveries []Discovered, err error) {
|
||||||
|
s := Settings{}
|
||||||
|
if len(settings) > 0 {
|
||||||
|
s = settings[0]
|
||||||
|
}
|
||||||
|
p, err := initialize(s)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
p.RLock()
|
p.RLock()
|
||||||
address := p.settings.MulticastAddress + ":" + p.settings.Port
|
address := p.settings.MulticastAddress + ":" + p.settings.Port
|
||||||
portNum := p.settings.portNum
|
portNum := p.settings.portNum
|
||||||
|
@ -188,12 +200,13 @@ func (p *PeerDiscovery) Discover() (discoveries []Discovered, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
maxDatagramSize = 65507
|
// https://en.wikipedia.org/wiki/User_Datagram_Protocol#Packet_structure
|
||||||
|
maxDatagramSize = 66507
|
||||||
)
|
)
|
||||||
|
|
||||||
// Listen binds to the UDP address and port given and writes packets received
|
// Listen binds to the UDP address and port given and writes packets received
|
||||||
// from that address to a buffer which is passed to a hander
|
// from that address to a buffer which is passed to a hander
|
||||||
func (p *PeerDiscovery) listen() (recievedBytes []byte, err error) {
|
func (p *peerDiscovery) listen() (recievedBytes []byte, err error) {
|
||||||
p.RLock()
|
p.RLock()
|
||||||
address := p.settings.MulticastAddress + ":" + p.settings.Port
|
address := p.settings.MulticastAddress + ":" + p.settings.Port
|
||||||
portNum := p.settings.portNum
|
portNum := p.settings.portNum
|
||||||
|
|
24
vendor/github.com/schollz/peerdiscovery/peerdiscovery_test.go
generated
vendored
24
vendor/github.com/schollz/peerdiscovery/peerdiscovery_test.go
generated
vendored
|
@ -7,34 +7,14 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSettings(t *testing.T) {
|
|
||||||
_, err := New()
|
|
||||||
assert.Nil(t, err)
|
|
||||||
|
|
||||||
_, err = New(Settings{
|
|
||||||
Limit: -1,
|
|
||||||
Payload: []byte("payload"),
|
|
||||||
Delay: 500 * time.Millisecond,
|
|
||||||
TimeLimit: 10 * time.Second,
|
|
||||||
})
|
|
||||||
assert.Nil(t, err)
|
|
||||||
|
|
||||||
_, err = New(Settings{
|
|
||||||
MulticastAddress: "assd.asdf.asdf.asfd",
|
|
||||||
})
|
|
||||||
assert.NotNil(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDiscovery(t *testing.T) {
|
func TestDiscovery(t *testing.T) {
|
||||||
p, _ := New(Settings{
|
// should not be able to "discover" itself
|
||||||
|
discoveries, err := Discover(Settings{
|
||||||
Limit: -1,
|
Limit: -1,
|
||||||
Payload: []byte("payload"),
|
Payload: []byte("payload"),
|
||||||
Delay: 500 * time.Millisecond,
|
Delay: 500 * time.Millisecond,
|
||||||
TimeLimit: 5 * time.Second,
|
TimeLimit: 5 * time.Second,
|
||||||
})
|
})
|
||||||
|
|
||||||
// should not be able to "discover" itself
|
|
||||||
discoveries, err := p.Discover()
|
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Zero(t, len(discoveries))
|
assert.Zero(t, len(discoveries))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue