More of the protocol
This commit is contained in:
parent
febea0b653
commit
53d6a21d5d
3 changed files with 50 additions and 2 deletions
|
@ -20,6 +20,7 @@ import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RIReqPacket struct {
|
type RIReqPacket struct {
|
||||||
|
@ -78,6 +79,17 @@ func parseRIUpd(p []byte) (*RIUpdPacket, error) {
|
||||||
|
|
||||||
type NetworkTuples []NetworkTuple
|
type NetworkTuples []NetworkTuple
|
||||||
|
|
||||||
|
func (n NetworkTuples) String() string {
|
||||||
|
var sb strings.Builder
|
||||||
|
for i, nt := range n {
|
||||||
|
if i > 0 {
|
||||||
|
sb.WriteString(", ")
|
||||||
|
}
|
||||||
|
fmt.Fprintf(&sb, "%d-%d dist %d", nt.RangeStart, nt.RangeEnd, nt.Distance)
|
||||||
|
}
|
||||||
|
return sb.String()
|
||||||
|
}
|
||||||
|
|
||||||
func (n NetworkTuples) WriteTo(w io.Writer) (int64, error) {
|
func (n NetworkTuples) WriteTo(w io.Writer) (int64, error) {
|
||||||
a := acc(w)
|
a := acc(w)
|
||||||
for _, nt := range n {
|
for _, nt := range n {
|
||||||
|
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Subcode is used to distinguish types of zone request/response.
|
// Subcode is used to distinguish types of zone request/response.
|
||||||
|
@ -285,6 +286,17 @@ func parseGZNRspPacket(p []byte) (*GZNRspPacket, error) {
|
||||||
|
|
||||||
type ZoneTuples []ZoneTuple
|
type ZoneTuples []ZoneTuple
|
||||||
|
|
||||||
|
func (zs ZoneTuples) String() string {
|
||||||
|
var sb strings.Builder
|
||||||
|
for i, zt := range zs {
|
||||||
|
if i > 0 {
|
||||||
|
sb.WriteString(", ")
|
||||||
|
}
|
||||||
|
fmt.Fprintf(&sb, "%d %q", zt.Network, zt.Name)
|
||||||
|
}
|
||||||
|
return sb.String()
|
||||||
|
}
|
||||||
|
|
||||||
type ZoneTuple struct {
|
type ZoneTuple struct {
|
||||||
Network uint16
|
Network uint16
|
||||||
Name string
|
Name string
|
||||||
|
|
28
peer.go
28
peer.go
|
@ -240,6 +240,7 @@ func (p *peer) handle(ctx context.Context) error {
|
||||||
log.Printf("Couldn't send RI-Req packet: %v", err)
|
log.Printf("Couldn't send RI-Req packet: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
rstate = rsWaitForRIRsp
|
||||||
|
|
||||||
case *aurp.RIReqPacket:
|
case *aurp.RIReqPacket:
|
||||||
if sstate != ssConnected {
|
if sstate != ssConnected {
|
||||||
|
@ -256,6 +257,7 @@ func (p *peer) handle(ctx context.Context) error {
|
||||||
p.tr.LocalSeq = 1
|
p.tr.LocalSeq = 1
|
||||||
if _, err := p.send(p.tr.NewRIRspPacket(aurp.RoutingFlagLast, nets)); err != nil {
|
if _, err := p.send(p.tr.NewRIRspPacket(aurp.RoutingFlagLast, nets)); err != nil {
|
||||||
log.Printf("Couldn't send RI-Rsp packet: %v", err)
|
log.Printf("Couldn't send RI-Rsp packet: %v", err)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
sstate = ssWaitForRIAck1
|
sstate = ssWaitForRIAck1
|
||||||
|
|
||||||
|
@ -263,9 +265,18 @@ func (p *peer) handle(ctx context.Context) error {
|
||||||
if rstate != rsWaitForRIRsp {
|
if rstate != rsWaitForRIRsp {
|
||||||
log.Printf("Received RI-Rsp but was not waiting for one (receiver state was %v)", rstate)
|
log.Printf("Received RI-Rsp but was not waiting for one (receiver state was %v)", rstate)
|
||||||
}
|
}
|
||||||
// TODO: Repsond with RI-Ack
|
|
||||||
|
log.Printf("Learned about these networks: %v", pkt.Networks)
|
||||||
|
|
||||||
// TODO: Integrate info into route table
|
// TODO: Integrate info into route table
|
||||||
|
|
||||||
|
// TODO: track which networks we don't have zone info for, and
|
||||||
|
// only set SZI for those ?
|
||||||
|
if _, err := p.send(p.tr.NewRIAckPacket(pkt.ConnectionID, pkt.Sequence, aurp.RoutingFlagSendZoneInfo)); err != nil {
|
||||||
|
log.Printf("Couldn't send RI-Ack packet: %v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
case *aurp.RIAckPacket:
|
case *aurp.RIAckPacket:
|
||||||
switch sstate {
|
switch sstate {
|
||||||
case ssWaitForRIAck1:
|
case ssWaitForRIAck1:
|
||||||
|
@ -285,6 +296,8 @@ func (p *peer) handle(ctx context.Context) error {
|
||||||
sstate = ssConnected
|
sstate = ssConnected
|
||||||
|
|
||||||
// If SZI flag is set, send ZI-Rsp (transaction)
|
// If SZI flag is set, send ZI-Rsp (transaction)
|
||||||
|
// TODO: only respond with zones for networks that were in the
|
||||||
|
// RI-Rsp that corresponded to this RI-Ack
|
||||||
if pkt.Flags&aurp.RoutingFlagSendZoneInfo != 0 {
|
if pkt.Flags&aurp.RoutingFlagSendZoneInfo != 0 {
|
||||||
zones := aurp.ZoneTuples{
|
zones := aurp.ZoneTuples{
|
||||||
{
|
{
|
||||||
|
@ -318,10 +331,21 @@ func (p *peer) handle(ctx context.Context) error {
|
||||||
rstate = rsUnconnected
|
rstate = rsUnconnected
|
||||||
|
|
||||||
case *aurp.ZIReqPacket:
|
case *aurp.ZIReqPacket:
|
||||||
// TODO: Respond with ZI-Rsp
|
// TODO: only respond with zones for networks specified by the
|
||||||
|
// ZI-Req
|
||||||
|
zones := aurp.ZoneTuples{
|
||||||
|
{
|
||||||
|
Network: p.cfg.EtherTalk.NetStart,
|
||||||
|
Name: p.cfg.EtherTalk.ZoneName,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if _, err := p.send(p.tr.NewZIRspPacket(zones)); err != nil {
|
||||||
|
log.Printf("Couldn't send ZI-Rsp packet: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
case *aurp.ZIRspPacket:
|
case *aurp.ZIRspPacket:
|
||||||
// TODO: Integrate info into zone table
|
// TODO: Integrate info into zone table
|
||||||
|
log.Printf("Learned about these zones: %v", pkt.Zones)
|
||||||
|
|
||||||
case *aurp.TicklePacket:
|
case *aurp.TicklePacket:
|
||||||
// Immediately respond with Tickle-Ack
|
// Immediately respond with Tickle-Ack
|
||||||
|
|
Loading…
Reference in a new issue