Skip to content

Commit

Permalink
Revert "fix typo and make message types constant"
Browse files Browse the repository at this point in the history
  • Loading branch information
kung-foo authored Sep 4, 2020
1 parent e7f3d1d commit 4969c5e
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions uacp/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ 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 @@ -182,7 +177,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 @@ -193,7 +188,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 @@ -213,7 +208,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 @@ -238,7 +233,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 @@ -248,14 +243,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 @@ -276,7 +271,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 @@ -324,7 +319,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 == ERRF {
if h.MessageType == "ERR" {
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 @@ -372,5 +367,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 4969c5e

Please sign in to comment.