mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-25 23:01:38 +00:00
Update errors, update Write
This commit is contained in:
parent
160e01e84f
commit
b2f4f2e1b6
@ -271,7 +271,8 @@ func main() {
|
|||||||
// Some stuff
|
// Some stuff
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(time.Second * 2)
|
time.Sleep(time.Second * 2)
|
||||||
session, err := n.core.Dial("nodeid", "babd4e4bccb216f77bb723c1b034b63a652060aabfe9506b51f687183e9b0fd13f438876f5a3ab21cac9c8101eb88e2613fe2a8b0724add09d7ef5a72146c31f")
|
//session, err := n.core.Dial("nodeid", "babd4e4bccb216f77bb723c1b034b63a652060aabfe9506b51f687183e9b0fd13f438876f5a3ab21cac9c8101eb88e2613fe2a8b0724add09d7ef5a72146c31f")
|
||||||
|
session, err := n.core.Dial("nodeid", "9890e135604e8aa6039a909e40c629824d852042a70e51957d5b9d700195663d50552e8e869af132b4617d76f8ef00314d94cce23aa8d6b051b3b952a32a4966")
|
||||||
logger.Println(session, err)
|
logger.Println(session, err)
|
||||||
b := []byte{1, 2, 3, 4, 5}
|
b := []byte{1, 2, 3, 4, 5}
|
||||||
for {
|
for {
|
||||||
|
@ -100,17 +100,17 @@ func (c *Conn) startSearch() {
|
|||||||
|
|
||||||
func (c *Conn) Read(b []byte) (int, error) {
|
func (c *Conn) Read(b []byte) (int, error) {
|
||||||
if c.session == nil {
|
if c.session == nil {
|
||||||
return 0, errors.New("invalid session")
|
return 0, errors.New("session not open")
|
||||||
}
|
}
|
||||||
p := <-c.session.recv
|
p := <-c.session.recv
|
||||||
defer util.PutBytes(p.Payload)
|
defer util.PutBytes(p.Payload)
|
||||||
if !c.session.nonceIsOK(&p.Nonce) {
|
if !c.session.nonceIsOK(&p.Nonce) {
|
||||||
return 0, errors.New("invalid nonce")
|
return 0, errors.New("packet dropped due to invalid nonce")
|
||||||
}
|
}
|
||||||
bs, isOK := crypto.BoxOpen(&c.session.sharedSesKey, p.Payload, &p.Nonce)
|
bs, isOK := crypto.BoxOpen(&c.session.sharedSesKey, p.Payload, &p.Nonce)
|
||||||
if !isOK {
|
if !isOK {
|
||||||
util.PutBytes(bs)
|
util.PutBytes(bs)
|
||||||
return 0, errors.New("failed to decrypt")
|
return 0, errors.New("packet dropped due to decryption failure")
|
||||||
}
|
}
|
||||||
b = b[:0]
|
b = b[:0]
|
||||||
b = append(b, bs...)
|
b = append(b, bs...)
|
||||||
@ -125,7 +125,7 @@ func (c *Conn) Write(b []byte) (int, error) {
|
|||||||
c.core.router.doAdmin(func() {
|
c.core.router.doAdmin(func() {
|
||||||
c.startSearch()
|
c.startSearch()
|
||||||
})
|
})
|
||||||
return 0, errors.New("invalid session")
|
return 0, errors.New("session not open")
|
||||||
}
|
}
|
||||||
defer util.PutBytes(b)
|
defer util.PutBytes(b)
|
||||||
if !c.session.init {
|
if !c.session.init {
|
||||||
@ -146,7 +146,7 @@ func (c *Conn) Write(b []byte) (int, error) {
|
|||||||
packet := p.encode()
|
packet := p.encode()
|
||||||
c.session.bytesSent += uint64(len(b))
|
c.session.bytesSent += uint64(len(b))
|
||||||
c.session.send <- packet
|
c.session.send <- packet
|
||||||
//c.session.core.router.out(packet)
|
c.session.core.router.out(packet)
|
||||||
return len(b), nil
|
return len(b), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -523,7 +523,7 @@ func (ss *sessions) resetInits() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/*
|
||||||
// This is for a per-session worker.
|
// This is for a per-session worker.
|
||||||
// It handles calling the relatively expensive crypto operations.
|
// It handles calling the relatively expensive crypto operations.
|
||||||
// It's also responsible for checking nonces and dropping out-of-date/duplicate packets, or else calling the function to update nonces if the packet is OK.
|
// It's also responsible for checking nonces and dropping out-of-date/duplicate packets, or else calling the function to update nonces if the packet is OK.
|
||||||
|
Loading…
Reference in New Issue
Block a user