Skip to content

Commit

Permalink
Merge pull request #138 from loopholelabs/staging
Browse files Browse the repository at this point in the history
Release v0.5.2
  • Loading branch information
ShivanshVij authored Jul 22, 2022
2 parents 0799cec + ef78f48 commit a8f9481
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .trunk/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*out
*log
*logs
24 changes: 23 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [v0.5.2] - 2022-07-22 (Beta)

## Features

- Adding the `SetHandlerTable` function to the server which allows us to modify the handler table in the server

## Changes

- Close errors when the connection is already closed will now log at the Debug level

## [v0.5.1] - 2022-07-20 (Beta)

## Fixes
Expand Down Expand Up @@ -278,16 +288,28 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

Initial Release of Frisbee

[unreleased]: https://github.com/loopholelabs/frisbee/compare/v0.5.1...HEAD
[unreleased]: https://github.com/loopholelabs/frisbee/compare/v0.5.2...HEAD

[v0.5.2]: https://github.com/loopholelabs/frisbee/compare/v0.5.1...v0.5.2

[v0.5.1]: https://github.com/loopholelabs/frisbee/compare/v0.5.0...v0.5.1

[v0.5.0]: https://github.com/loopholelabs/frisbee/compare/v0.4.6...v0.5.0

[v0.4.6]: https://github.com/loopholelabs/frisbee/compare/v0.4.5...v0.4.6

[v0.4.5]: https://github.com/loopholelabs/frisbee/compare/v0.4.4...v0.4.5

[v0.4.4]: https://github.com/loopholelabs/frisbee/compare/v0.4.3...v0.4.4

[v0.4.3]: https://github.com/loopholelabs/frisbee/compare/v0.4.2...v0.4.3

[v0.4.2]: https://github.com/loopholelabs/frisbee/compare/v0.4.1...v0.4.2

[v0.4.1]: https://github.com/loopholelabs/frisbee/compare/v0.4.0...v0.4.1

[v0.4.0]: https://github.com/loopholelabs/frisbee/compare/v0.3.2...v0.4.0

[v0.3.2]: https://github.com/loopholelabs/frisbee/compare/v0.3.1...v0.3.2
[v0.3.1]: https://github.com/loopholelabs/frisbee/compare/v0.3.0...v0.3.1
[v0.3.0]: https://github.com/loopholelabs/frisbee/compare/v0.2.4...v0.3.0
Expand Down
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ LOOP:
}
p, err = c.conn.ReadPacket()
if err != nil {
c.Logger().Error().Err(err).Msg("error while getting packet frisbee connection")
c.Logger().Debug().Err(err).Msg("error while getting packet frisbee connection")
c.wg.Done()
_ = c.Close()
return
Expand Down
51 changes: 30 additions & 21 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,30 +79,18 @@ type Server struct {
// NewServer returns an uninitialized frisbee Server with the registered HandlerTable.
// The Start method must then be called to start the server and listen for connections.
func NewServer(handlerTable HandlerTable, opts ...Option) (*Server, error) {
for i := uint16(0); i < RESERVED9; i++ {
if _, ok := handlerTable[i]; ok {
return nil, InvalidHandlerTable
}
}

options := loadOptions(opts...)
if options.Heartbeat > time.Duration(0) {
handlerTable[HEARTBEAT] = func(_ context.Context, incoming *packet.Packet) (outgoing *packet.Packet, action Action) {
outgoing = incoming
return
}
s := &Server{
options: options,
shutdown: atomic.NewBool(false),
connections: make(map[*Async]struct{}),
startedCh: make(chan struct{}),
baseContext: defaultBaseContext,
onClosed: defaultOnClosed,
preWrite: defaultPreWrite,
}

return &Server{
handlerTable: handlerTable,
options: options,
shutdown: atomic.NewBool(false),
connections: make(map[*Async]struct{}),
startedCh: make(chan struct{}),
baseContext: defaultBaseContext,
onClosed: defaultOnClosed,
preWrite: defaultPreWrite,
}, nil
return s, s.SetHandlerTable(handlerTable)
}

// SetBaseContext sets the baseContext function for the server. If f is nil, it returns an error.
Expand Down Expand Up @@ -132,6 +120,27 @@ func (s *Server) SetPreWrite(f func()) error {
return nil
}

// SetHandlerTable sets the handler table for the server.
//
// This function should not be called once the server has started.
func (s *Server) SetHandlerTable(handlerTable HandlerTable) error {
for i := uint16(0); i < RESERVED9; i++ {
if _, ok := handlerTable[i]; ok {
return InvalidHandlerTable
}
}

if s.options.Heartbeat > time.Duration(0) {
handlerTable[HEARTBEAT] = func(_ context.Context, incoming *packet.Packet) (outgoing *packet.Packet, action Action) {
outgoing = incoming
return
}
}

s.handlerTable = handlerTable
return nil
}

// Start will start the frisbee server and its reactor goroutines
// to receive and handle incoming connections. If the baseContext, ConnContext,
// onClosed, OnShutdown, or preWrite functions have not been defined, it will
Expand Down

0 comments on commit a8f9481

Please sign in to comment.