Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
discosrv
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Ind.ie Projects
discosrv
Commits
14c68eb8
Commit
14c68eb8
authored
Dec 22, 2013
by
Jakob Borg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
External discover
parents
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
0 deletions
+75
-0
.gitignore
.gitignore
+1
-0
main.go
main.go
+74
-0
No files found.
.gitignore
0 → 100644
View file @
14c68eb8
discosrv
main.go
0 → 100644
View file @
14c68eb8
package
main
import
(
"log"
"net"
"sync"
"github.com/calmh/syncthing/discover"
)
type
Node
struct
{
IP
[]
byte
Port
uint16
}
var
(
nodes
=
make
(
map
[
string
]
Node
)
lock
sync
.
Mutex
)
func
main
()
{
addr
,
_
:=
net
.
ResolveUDPAddr
(
"udp"
,
":22025"
)
conn
,
err
:=
net
.
ListenUDP
(
"udp"
,
addr
)
if
err
!=
nil
{
panic
(
err
)
}
var
buf
=
make
([]
byte
,
1024
)
for
{
n
,
addr
,
err
:=
conn
.
ReadFromUDP
(
buf
)
if
err
!=
nil
{
panic
(
err
)
}
pkt
,
err
:=
discover
.
DecodePacket
(
buf
[
:
n
])
if
err
!=
nil
{
log
.
Println
(
"Warning:"
,
err
)
continue
}
switch
pkt
.
Magic
{
case
0x20121025
:
// Announcement
//lock.Lock()
ip
:=
addr
.
IP
.
To4
()
if
ip
==
nil
{
ip
=
addr
.
IP
.
To16
()
}
node
:=
Node
{
ip
,
uint16
(
pkt
.
Port
)}
log
.
Println
(
"<-"
,
pkt
.
ID
,
node
)
nodes
[
pkt
.
ID
]
=
node
//lock.Unlock()
case
0x19760309
:
// Query
//lock.Lock()
node
,
ok
:=
nodes
[
pkt
.
ID
]
//lock.Unlock()
if
ok
{
pkt
:=
discover
.
Packet
{
Magic
:
0x20121025
,
ID
:
pkt
.
ID
,
Port
:
node
.
Port
,
IP
:
node
.
IP
,
}
_
,
_
,
err
=
conn
.
WriteMsgUDP
(
discover
.
EncodePacket
(
pkt
),
nil
,
addr
)
if
err
!=
nil
{
log
.
Println
(
"Warning:"
,
err
)
}
else
{
log
.
Println
(
"->"
,
pkt
.
ID
,
node
)
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment