Update errors, update Write

This commit is contained in:
Neil Alexander 2019-04-19 00:07:26 +01:00
parent 160e01e84f
commit b2f4f2e1b6
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
3 changed files with 8 additions and 7 deletions

View File

@ -271,7 +271,8 @@ func main() {
// Some stuff
go func() {
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)
b := []byte{1, 2, 3, 4, 5}
for {

View File

@ -100,17 +100,17 @@ func (c *Conn) startSearch() {
func (c *Conn) Read(b []byte) (int, error) {
if c.session == nil {
return 0, errors.New("invalid session")
return 0, errors.New("session not open")
}
p := <-c.session.recv
defer util.PutBytes(p.Payload)
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)
if !isOK {
util.PutBytes(bs)
return 0, errors.New("failed to decrypt")
return 0, errors.New("packet dropped due to decryption failure")
}
b = b[:0]
b = append(b, bs...)
@ -125,7 +125,7 @@ func (c *Conn) Write(b []byte) (int, error) {
c.core.router.doAdmin(func() {
c.startSearch()
})
return 0, errors.New("invalid session")
return 0, errors.New("session not open")
}
defer util.PutBytes(b)
if !c.session.init {
@ -146,7 +146,7 @@ func (c *Conn) Write(b []byte) (int, error) {
packet := p.encode()
c.session.bytesSent += uint64(len(b))
c.session.send <- packet
//c.session.core.router.out(packet)
c.session.core.router.out(packet)
return len(b), nil
}

View File

@ -523,7 +523,7 @@ func (ss *sessions) resetInits() {
}
////////////////////////////////////////////////////////////////////////////////
/*
// This is for a per-session worker.
// 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.