Skip to content

Commit

Permalink
fix typo and make types constant
Browse files Browse the repository at this point in the history
  • Loading branch information
kung-foo committed Sep 3, 2020
1 parent cd558d8 commit 4b938ca
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions uacp/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ const (
DefaultSendBufSize = 0xffff
DefaultMaxChunkCount = 512
DefaultMaxMessageSize = 2 * MB

ERRF = "ERRF"
ACKF = "ACKF"
HELF = "HELF"
RHEF = "RHEF"
)

// connid stores the current connection id. updated with atomic.AddUint32
Expand Down Expand Up @@ -177,7 +182,7 @@ func (c *Conn) handshake(endpoint string) error {
EndpointURL: endpoint,
}

if err := c.Send("HELF", hel); err != nil {
if err := c.Send(HELF, hel); err != nil {
return err
}

Expand All @@ -188,7 +193,7 @@ func (c *Conn) handshake(endpoint string) error {

msgtyp := string(b[:4])
switch msgtyp {
case "ACKF":
case ACKF:
ack := new(Acknowledge)
if _, err := ack.Decode(b[hdrlen:]); err != nil {
return errors.Errorf("uacp: decode ACK failed: %s", err)
Expand All @@ -208,7 +213,7 @@ func (c *Conn) handshake(endpoint string) error {
debug.Printf("conn %d: recv %#v", c.id, ack)
return nil

case "ERRF":
case ERRF:
errf := new(Error)
if _, err := errf.Decode(b[hdrlen:]); err != nil {
return errors.Errorf("uacp: decode ERR failed: %s", err)
Expand All @@ -233,7 +238,7 @@ func (c *Conn) srvhandshake(endpoint string) error {
msgtyp := string(b[:4])
msg := b[hdrlen:]
switch msgtyp {
case "HELF":
case HELF:
hel := new(Hello)
if _, err := hel.Decode(msg); err != nil {
c.SendError(ua.StatusBadTCPInternalError)
Expand All @@ -243,14 +248,14 @@ func (c *Conn) srvhandshake(endpoint string) error {
c.SendError(ua.StatusBadTCPEndpointURLInvalid)
return errors.Errorf("uacp: invalid endpoint url %s", hel.EndpointURL)
}
if err := c.Send("ACKF", c.ack); err != nil {
if err := c.Send(ACKF, c.ack); err != nil {
c.SendError(ua.StatusBadTCPInternalError)
return err
}
debug.Printf("conn %d: recv %#v", c.id, hel)
return nil

case "RHEF":
case RHEF:
rhe := new(ReverseHello)
if _, err := rhe.Decode(msg); err != nil {
c.SendError(ua.StatusBadTCPInternalError)
Expand All @@ -271,7 +276,7 @@ func (c *Conn) srvhandshake(endpoint string) error {
debug.Printf("conn %d: recv %#v", c.id, rhe)
return nil

case "ERRF":
case ERRF:
errf := new(Error)
if _, err := errf.Decode(b[hdrlen:]); err != nil {
return errors.Errorf("uacp: decode ERR failed: %s", err)
Expand Down Expand Up @@ -319,7 +324,7 @@ func (c *Conn) Receive() ([]byte, error) {

debug.Printf("conn %d: recv %s%c with %d bytes", c.id, h.MessageType, h.ChunkType, h.MessageSize)

if h.MessageType == "ERR" {
if h.MessageType == ERRF {
errf := new(Error)
if _, err := errf.Decode(b[hdrlen:h.MessageSize]); err != nil {
return nil, errors.Errorf("uacp: failed to decode ERRF message: %s", err)
Expand Down Expand Up @@ -367,5 +372,5 @@ func (c *Conn) SendError(code ua.StatusCode) {
// we swallow the error to silence complaints from the linter
// since sending an error will close the connection and we
// want to bubble a different error up.
_ = c.Send("ERRF", &Error{ErrorCode: uint32(code)})
_ = c.Send(ERRF, &Error{ErrorCode: uint32(code)})
}

0 comments on commit 4b938ca

Please sign in to comment.