Skip to content

Commit

Permalink
Fix: forever read + Feat: listen on unix socket
Browse files Browse the repository at this point in the history
  • Loading branch information
yunginnanet committed Oct 4, 2022
1 parent 78b145d commit 82d1803
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 228 deletions.
50 changes: 50 additions & 0 deletions builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package putxt

import (
"time"

"git.tcp.direct/kayos/common/pool"
"github.com/yunginnanet/Rate5"
)

type TermDumpster struct {
gzip bool
maxSize int64
timeout time.Duration
handler Handler
log Logger
Pool pool.BufferFactory
*rate5.Limiter
}

func NewTermDumpster(handler Handler) *TermDumpster {
td := &TermDumpster{
maxSize: 3 << 20,
timeout: 5 * time.Second,
Limiter: rate5.NewStrictLimiter(60, 5),
handler: handler,
log: dummyLogger{},
Pool: pool.NewBufferFactory(),
}
return td
}

func (td *TermDumpster) WithGzip() *TermDumpster {
td.gzip = true
return td
}

func (td *TermDumpster) WithMaxSize(size int64) *TermDumpster {
td.maxSize = size
return td
}

func (td *TermDumpster) WithTimeout(timeout time.Duration) *TermDumpster {
td.timeout = timeout
return td
}

func (td *TermDumpster) WithLogger(logger Logger) *TermDumpster {
td.log = logger
return td
}
38 changes: 0 additions & 38 deletions cmd/termbintest.go

This file was deleted.

5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ module git.tcp.direct/kayos/putxt
go 1.18

require (
git.tcp.direct/kayos/common v0.7.0
git.tcp.direct/kayos/common v0.7.5
github.com/yunginnanet/Rate5 v1.1.0
golang.org/x/tools v0.1.12
inet.af/netaddr v0.0.0-20220617031823-097006376321
inet.af/netaddr v0.0.0-20220811202034-502d2d690317
)

require (
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
go4.org/intern v0.0.0-20211027215823-ae77deb06f29 // indirect
go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760 // indirect
nullprogram.com/x/rng v1.1.0 // indirect
)
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
git.tcp.direct/kayos/common v0.7.0 h1:KZDwoCzUiwQaYSWESr080N8wUVyLD27QYgzXgc7LiAQ=
git.tcp.direct/kayos/common v0.7.0/go.mod h1:7tMZBVNPLFSZk+JXTA6pgXWpf/XHqYRfT7Q3OziI++Y=
git.tcp.direct/kayos/common v0.7.5 h1:a95oIv3pzRwzYaINqFASnXqXOWVWupIVWHcOtTVUOHU=
git.tcp.direct/kayos/common v0.7.5/go.mod h1:jVbdX9prBrx9e3aTsNpu643brGVgpLvysl40/F5U2cE=
github.com/dvyukov/go-fuzz v0.0.0-20210103155950-6a8e9d1f2415/go.mod h1:11Gm+ccJnvAhCNLlf5+cS9KjtbaD5I5zaZpFMsTHWTw=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
Expand Down Expand Up @@ -34,5 +34,7 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
inet.af/netaddr v0.0.0-20220617031823-097006376321 h1:B4dC8ySKTQXasnjDTMsoCMf1sQG4WsMej0WXaHxunmU=
inet.af/netaddr v0.0.0-20220617031823-097006376321/go.mod h1:OIezDfdzOgFhuw4HuWapWq2e9l0H9tK4F1j+ETRtF3k=
inet.af/netaddr v0.0.0-20220811202034-502d2d690317 h1:U2fwK6P2EqmopP/hFLTOAjWTki0qgd4GMJn5X8wOleU=
inet.af/netaddr v0.0.0-20220811202034-502d2d690317/go.mod h1:OIezDfdzOgFhuw4HuWapWq2e9l0H9tK4F1j+ETRtF3k=
nullprogram.com/x/rng v1.1.0 h1:SMU7DHaQSWtKJNTpNFIFt8Wd/KSmOuSDPXrMFp/UMro=
nullprogram.com/x/rng v1.1.0/go.mod h1:glGw6V87vyfawxCzqOABL3WfL95G65az9Z2JZCylCkg=
20 changes: 20 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package putxt

import "fmt"

const (
MessageRatelimited = "RATELIMIT_REACHED"
MessageSizeLimited = "MAX_SIZE_EXCEEDED"
MessageBinaryData = "BINARY_DATA_REJECTED"
MessageInternalError = "INTERNAL_ERROR"
)

type Logger interface {
Printf(format string, v ...interface{})
}

type dummyLogger struct{}

func (dummyLogger) Printf(format string, v ...interface{}) {
_, _ = fmt.Printf(format, v...)
}
184 changes: 0 additions & 184 deletions main.go

This file was deleted.

Loading

0 comments on commit 82d1803

Please sign in to comment.