Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
henrod committed May 23, 2019
1 parent 42c83d3 commit 46473a2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
28 changes: 24 additions & 4 deletions acceptorwrapper/rate_limiting.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
// Copyright (c) TFG Co. All Rights Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

package acceptorwrapper

import (
Expand All @@ -12,13 +32,13 @@ type RateLimitingWrapper struct {

// NewRateLimitingWrapper ...
func NewRateLimitingWrapper() *RateLimitingWrapper {
return &RateLimitingWrapper{
BaseWrapper: NewBaseWrapper(),
}
r := &RateLimitingWrapper{}
r.BaseWrapper = NewBaseWrapper(r.wrapConn)
return r
}

// WrapConn ...
func (r *RateLimitingWrapper) WrapConn(conn net.Conn) net.Conn {
func (r *RateLimitingWrapper) wrapConn(conn net.Conn) net.Conn {
// TODOhenrod: get this from config
return NewRateLimitingConn(conn, 1, time.Minute)
}
13 changes: 5 additions & 8 deletions acceptorwrapper/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,24 @@ import (
// Wrapper ...
type Wrapper interface {
Wrap(acceptor.Acceptor) acceptor.Acceptor
WrapConn(net.Conn) net.Conn
}

// BaseWrapper ...
type BaseWrapper struct {
acceptor.Acceptor
connChan chan net.Conn
wrapConn func(net.Conn) net.Conn
}

// NewBaseWrapper ...
func NewBaseWrapper() BaseWrapper {
func NewBaseWrapper(wrapConn func(net.Conn) net.Conn) BaseWrapper {
return BaseWrapper{
connChan: make(chan net.Conn),
wrapConn: wrapConn,
}
}

// WrapConn ...
// MustImplement
func (b *BaseWrapper) WrapConn(net.Conn) net.Conn {
return nil
}

// Wrap ...
func (b *BaseWrapper) Wrap(a acceptor.Acceptor) acceptor.Acceptor {
b.Acceptor = a
Expand All @@ -69,7 +66,7 @@ func (b *BaseWrapper) GetConnChan() chan net.Conn {

func (b *BaseWrapper) pipe() {
for conn := range b.Acceptor.GetConnChan() {
b.connChan <- b.WrapConn(conn)
b.connChan <- b.wrapConn(conn)
}
}

Expand Down

0 comments on commit 46473a2

Please sign in to comment.