Skip to content

Commit

Permalink
Merge pull request #77 from loopholelabs/staging
Browse files Browse the repository at this point in the history
Releasing v0.2.5
  • Loading branch information
ShivanshVij committed Mar 11, 2022
2 parents 7c9cb67 + 96da05a commit c9874ba
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [v0.2.4] - 2022-03-11 (Beta)

### Changes

- Update packet to `v0.2.5`
- Added `UpdateContext` function for both the server and client

## [v0.2.3] - 2022-03-10 (Beta)

### Changes
Expand Down Expand Up @@ -150,7 +157,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

Initial Release of Frisbee

[unreleased]: https://github.com/loopholelabs/frisbee/compare/v0.2.3...HEAD
[unreleased]: https://github.com/loopholelabs/frisbee/compare/v0.2.4...HEAD
[v0.2.4]: https://github.com/loopholelabs/frisbee/compare/v0.2.3...v0.2.4
[v0.2.3]: https://github.com/loopholelabs/frisbee/compare/v0.2.2...v0.2.3
[v0.2.2]: https://github.com/loopholelabs/frisbee/compare/v0.2.1...v0.2.2
[v0.2.1]: https://github.com/loopholelabs/frisbee/compare/v0.2.0...v0.2.1
Expand Down
8 changes: 8 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ type Client struct {
// PacketContext is used to define packet-specific contexts based on the incoming packet
// and is run whenever a new packet arrives
PacketContext func(context.Context, *packet.Packet) context.Context

// UpdateContext is used to update a handler-specific context whenever the returned
// Action from a handler is UPDATE
UpdateContext func(context.Context, *Async) context.Context
}

// NewClient returns an uninitialized frisbee Client with the registered ClientRouter.
Expand Down Expand Up @@ -201,6 +205,10 @@ LOOP:
}
switch action {
case NONE:
case UPDATE:
if c.UpdateContext != nil {
c.ctx = c.UpdateContext(c.ctx, c.conn)
}
case CLOSE:
c.Logger().Debug().Msgf("Closing connection %s because of CLOSE action", c.addr)
c.wg.Done()
Expand Down
3 changes: 3 additions & 0 deletions frisbee.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const (
// NONE is used to do nothing (default)
NONE = Action(iota)

// UPDATE is used to trigger an UpdateContext call on the Server or Client
UPDATE

// CLOSE is used to close the frisbee connection
CLOSE
)
Expand Down
8 changes: 8 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ type Server struct {
// and is run whenever a new packet arrives
PacketContext func(context.Context, *packet.Packet) context.Context

// UpdateContext is used to update a handler-specific context whenever the returned
// Action from a handler is UPDATE
UpdateContext func(context.Context, *Async) context.Context

// OnClosed is a function run by the server whenever a connection is closed
OnClosed func(*Async, error)

Expand Down Expand Up @@ -228,6 +232,10 @@ HANDLE:
}
switch action {
case NONE:
case UPDATE:
if s.UpdateContext != nil {
connCtx = s.UpdateContext(connCtx, frisbeeConn)
}
case CLOSE:
_ = frisbeeConn.Close()
s.OnClosed(frisbeeConn, nil)
Expand Down

0 comments on commit c9874ba

Please sign in to comment.