Skip to content

Commit

Permalink
update deps
Browse files Browse the repository at this point in the history
Signed-off-by: SammyOina <[email protected]>
  • Loading branch information
SammyOina committed Oct 24, 2023
1 parent 2613c47 commit 41af358
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 122 deletions.
11 changes: 6 additions & 5 deletions coap/api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ func MakeCoAPHandler(svc coap.Service, l mflog.Logger) mux.HandlerFunc {
return handler
}

func sendResp(ctx context.Context, w mux.ResponseWriter, resp *message.Message) {
m := w.Conn().AcquireMessage(ctx)
func sendResp(w mux.ResponseWriter, resp *message.Message) {
m := w.Conn().AcquireMessage(w.Conn().Context())
defer w.Conn().ReleaseMessage(m)
m.SetCode(resp.Code)
m.SetBody(bytes.NewReader(resp.Payload))
m.SetToken(resp.Token)
Expand All @@ -85,7 +86,7 @@ func handler(w mux.ResponseWriter, m *mux.Message) {
Token: m.Token(),
Options: make(message.Options, 0, 16),
}
defer sendResp(m.Context(), w, &resp)
defer sendResp(w, &resp)
msg, err := decodeMessage(m)
if err != nil {
logger.Warn(fmt.Sprintf("Error decoding message: %s", err))
Expand All @@ -100,7 +101,7 @@ func handler(w mux.ResponseWriter, m *mux.Message) {
}
switch m.Code() {
case codes.GET:
err = handleGet(m.Context(), m, w.Conn(), msg, key)
err = handleGet(context.Background(), m, w, msg, key)
case codes.POST:
resp.Code = codes.Created
err = nil
Expand All @@ -122,7 +123,7 @@ func handler(w mux.ResponseWriter, m *mux.Message) {
}
}

func handleGet(ctx context.Context, m *mux.Message, c mux.Conn, msg *messaging.Message, key string) error {
func handleGet(ctx context.Context, m *mux.Message, c mux.ResponseWriter, msg *messaging.Message, key string) error {
var obs uint32
obs, err := m.Observe()
if err != nil {
Expand Down
22 changes: 13 additions & 9 deletions coap/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
"github.com/mainflux/mainflux/pkg/messaging"
"github.com/plgd-dev/go-coap/v3/message"
"github.com/plgd-dev/go-coap/v3/message/codes"
mux "github.com/plgd-dev/go-coap/v3/mux"
"github.com/plgd-dev/go-coap/v3/message/pool"
"github.com/plgd-dev/go-coap/v3/mux"
)

// Client wraps CoAP client.
Expand All @@ -36,14 +37,14 @@ type Client interface {
var ErrOption = errors.New("unable to set option")

type client struct {
client mux.Conn
client mux.ResponseWriter
token message.Token
observe uint32
logger logger.Logger
}

// NewClient instantiates a new Observer.
func NewClient(c mux.Conn, tkn message.Token, l logger.Logger) Client {
func NewClient(c mux.ResponseWriter, tkn message.Token, l logger.Logger) Client {
return &client{
client: c,
token: tkn,
Expand All @@ -53,25 +54,25 @@ func NewClient(c mux.Conn, tkn message.Token, l logger.Logger) Client {
}

func (c *client) Done() <-chan struct{} {
return c.client.Done()
return c.client.Conn().Done()
}

func (c *client) Cancel() error {
pm := c.client.AcquireMessage(context.Background())
pm := c.client.Conn().AcquireMessage(context.Background())
pm.SetCode(codes.Content)
pm.SetToken(c.token)
if err := c.client.WriteMessage(pm); err != nil {
if err := c.client.Conn().WriteMessage(pm); err != nil {
c.logger.Error(fmt.Sprintf("Error sending message: %s.", err))
}
return c.client.Close()
return c.client.Conn().Close()
}

func (c *client) Token() string {
return c.token.String()
}

func (c *client) Handle(msg *messaging.Message) error {
pm := c.client.AcquireMessage(context.Background())
pm := pool.NewMessage(context.Background())
pm.SetCode(codes.Content)
pm.SetToken(c.token)
pm.SetBody(bytes.NewReader(msg.Payload))
Expand Down Expand Up @@ -101,5 +102,8 @@ func (c *client) Handle(msg *messaging.Message) error {
for _, option := range opts {
pm.SetOptionBytes(option.ID, option.Value)
}
return c.client.WriteMessage(pm)
if err := c.client.Conn().WriteMessage(pm); err != nil {
return err
}
return nil
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/mainflux/mproxy => github.com/sammyoina/mproxy v0.0.0-20231006131650-51e30985e320
replace github.com/mainflux/mproxy => github.com/sammyoina/mproxy v0.0.0-20231022202359-ab4bb5fcaef1
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,8 @@ github.com/sagikazarmark/locafero v0.3.0 h1:zT7VEGWC2DTflmccN/5T1etyKvxSxpHsjb9c
github.com/sagikazarmark/locafero v0.3.0/go.mod h1:w+v7UsPNFwzF1cHuOajOOzoq4U7v/ig1mpRjqV+Bu1U=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
github.com/sammyoina/mproxy v0.0.0-20231006131650-51e30985e320 h1:Ak8XO7tAEUdIyTjr/G82e1S+1EiEa1FPjozYrEsPdSU=
github.com/sammyoina/mproxy v0.0.0-20231006131650-51e30985e320/go.mod h1:m3eBZLtl3exBRMfRqz52m+r2jPKKBV+NWLMeibnrgDA=
github.com/sammyoina/mproxy v0.0.0-20231022202359-ab4bb5fcaef1 h1:yYevls3tXYwRejhPnnw9poJiZWQZBb9MaUcq2Gj8Btk=
github.com/sammyoina/mproxy v0.0.0-20231022202359-ab4bb5fcaef1/go.mod h1:79BIGoxY//nKN8dQi9Y+NaVU/Gdn3s9IwLiMpLJqgDg=
github.com/sanity-io/litter v1.5.5 h1:iE+sBxPBzoK6uaEP5Lt3fHNgpKcHXc/A2HGETy0uJQo=
github.com/sanity-io/litter v1.5.5/go.mod h1:9gzJgR2i4ZpjZHsKvUXIRQVk7P+yM3e+jAF7bU2UI5U=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
Expand Down
107 changes: 4 additions & 103 deletions vendor/github.com/mainflux/mproxy/pkg/coap/coap.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ github.com/mailru/easyjson/jwriter
# github.com/mainflux/callhome v0.0.0-20230920140432-33c5663382ce
## explicit; go 1.21
github.com/mainflux/callhome/pkg/client
# github.com/mainflux/mproxy v0.3.1-0.20230822124450-4b4dfe600cc2 => github.com/sammyoina/mproxy v0.0.0-20231006131650-51e30985e320
# github.com/mainflux/mproxy v0.3.1-0.20230822124450-4b4dfe600cc2 => github.com/sammyoina/mproxy v0.0.0-20231022202359-ab4bb5fcaef1
## explicit; go 1.19
github.com/mainflux/mproxy/pkg/http
github.com/mainflux/mproxy/pkg/coap
Expand Down Expand Up @@ -1280,4 +1280,4 @@ gopkg.in/yaml.v2
# gopkg.in/yaml.v3 v3.0.1
## explicit
gopkg.in/yaml.v3
# github.com/mainflux/mproxy => github.com/sammyoina/mproxy v0.0.0-20231006131650-51e30985e320
# github.com/mainflux/mproxy => github.com/sammyoina/mproxy v0.0.0-20231022202359-ab4bb5fcaef1

0 comments on commit 41af358

Please sign in to comment.