added zeromq handling
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Paul 2022-03-11 23:34:09 +01:00
parent e828164392
commit 90136fe906
87 changed files with 6232 additions and 358 deletions

View File

@ -14,6 +14,8 @@ steps:
- name: build - name: build
image: golang image: golang
commands: commands:
- apt-get update -y
- apt-get install libczmq-dev
- go generate $SRCFILES - go generate $SRCFILES
- go build -o $PROJECTNAME $GOOPTIONS $SRCFILES - go build -o $PROJECTNAME $GOOPTIONS $SRCFILES
when: when:
@ -37,6 +39,8 @@ steps:
- name: build - name: build
image: golang image: golang
commands: commands:
- apt-get update -y
- apt-get install libczmq-dev
- go generate $SRCFILES - go generate $SRCFILES
- go build -o $PROJECTNAME $GOOPTIONS $SRCFILES - go build -o $PROJECTNAME $GOOPTIONS $SRCFILES
- tar -czvf $PROJECTNAME-$DRONE_TAG-$GOOS-$GOARCH.tar.gz $PROJECTNAME - tar -czvf $PROJECTNAME-$DRONE_TAG-$GOOS-$GOARCH.tar.gz $PROJECTNAME

View File

@ -10,6 +10,8 @@ import (
"git.paulbsd.com/paulbsd/ipbl/src/database" "git.paulbsd.com/paulbsd/ipbl/src/database"
"git.paulbsd.com/paulbsd/ipbl/src/models" "git.paulbsd.com/paulbsd/ipbl/src/models"
"git.paulbsd.com/paulbsd/ipbl/src/routers" "git.paulbsd.com/paulbsd/ipbl/src/routers"
"git.paulbsd.com/paulbsd/ipbl/src/zmqrouter"
"git.paulbsd.com/paulbsd/ipbl/utils"
_ "github.com/lib/pq" _ "github.com/lib/pq"
) )
@ -32,16 +34,10 @@ func main() {
defer cfg.Db.Close() defer cfg.Db.Close()
go models.ScanIP(&cfg) go models.ScanIP(&cfg)
go zmqrouter.Init(&cfg)
// Add cron task to handle them go func() { err = routers.RunServer(&ctx, &cfg) }()
//cr := cron.New()
//cr.AddFunc("0 * * * * *", func() {
// models.ScanIP(&cfg)
//})
//cr.Start()
err = routers.RunServer(&ctx, &cfg)
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
utils.Server()
} }

11
go.mod
View File

@ -3,14 +3,15 @@ module git.paulbsd.com/paulbsd/ipbl
go 1.17 go 1.17
require ( require (
github.com/labstack/echo/v4 v4.6.3 github.com/labstack/echo/v4 v4.7.0
github.com/lib/pq v1.10.4 github.com/lib/pq v1.10.4
gopkg.in/ini.v1 v1.66.4 gopkg.in/ini.v1 v1.66.4
gopkg.in/zeromq/goczmq.v4 v4.1.0
xorm.io/xorm v1.2.5 xorm.io/xorm v1.2.5
) )
require ( require (
github.com/goccy/go-json v0.9.4 // indirect github.com/goccy/go-json v0.9.5 // indirect
github.com/golang/snappy v0.0.4 // indirect github.com/golang/snappy v0.0.4 // indirect
github.com/json-iterator/go v1.1.12 // indirect github.com/json-iterator/go v1.1.12 // indirect
github.com/labstack/gommon v0.3.1 // indirect github.com/labstack/gommon v0.3.1 // indirect
@ -23,9 +24,9 @@ require (
github.com/syndtr/goleveldb v1.0.0 // indirect github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect github.com/valyala/fasttemplate v1.2.1 // indirect
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect
golang.org/x/text v0.3.7 // indirect golang.org/x/text v0.3.7 // indirect
xorm.io/builder v0.3.9 // indirect xorm.io/builder v0.3.9 // indirect
) )

12
go.sum
View File

@ -77,6 +77,8 @@ github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg78
github.com/goccy/go-json v0.7.4/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/goccy/go-json v0.7.4/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/goccy/go-json v0.9.4 h1:L8MLKG2mvVXiQu07qB6hmfqeSYQdOnqPot2GhsIwIaI= github.com/goccy/go-json v0.9.4 h1:L8MLKG2mvVXiQu07qB6hmfqeSYQdOnqPot2GhsIwIaI=
github.com/goccy/go-json v0.9.4/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/goccy/go-json v0.9.4/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/goccy/go-json v0.9.5 h1:ooSMW526ZjK+EaL5elrSyN2EzIfi/3V0m4+HJEDYLik=
github.com/goccy/go-json v0.9.5/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
@ -216,6 +218,8 @@ github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/labstack/echo/v4 v4.6.3 h1:VhPuIZYxsbPmo4m9KAkMU/el2442eB7EBFFhNTTT9ac= github.com/labstack/echo/v4 v4.6.3 h1:VhPuIZYxsbPmo4m9KAkMU/el2442eB7EBFFhNTTT9ac=
github.com/labstack/echo/v4 v4.6.3/go.mod h1:Hk5OiHj0kDqmFq7aHe7eDqI7CUhuCrfpupQtLGGLm7A= github.com/labstack/echo/v4 v4.6.3/go.mod h1:Hk5OiHj0kDqmFq7aHe7eDqI7CUhuCrfpupQtLGGLm7A=
github.com/labstack/echo/v4 v4.7.0 h1:8wHgZhoE9OT1NSLw6sfrX7ZGpWMtO5Zlfr68+BIo180=
github.com/labstack/echo/v4 v4.7.0/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks=
github.com/labstack/gommon v0.3.1 h1:OomWaJXm7xR6L1HmEtGyQf26TEn7V6X88mktX9kee9o= github.com/labstack/gommon v0.3.1 h1:OomWaJXm7xR6L1HmEtGyQf26TEn7V6X88mktX9kee9o=
github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM= github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
@ -410,6 +414,8 @@ golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 h1:f+lwQ+GtmgoY+A2YaQxlSOnDjXcQ7ZRLWOHbC6HtRqE= golang.org/x/crypto v0.0.0-20220214200702-86341886e292 h1:f+lwQ+GtmgoY+A2YaQxlSOnDjXcQ7ZRLWOHbC6HtRqE=
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70 h1:syTAU9FwmvzEoIYMqcPHOcVm4H3U5u90WsvuYgwpETU=
golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
@ -444,6 +450,8 @@ golang.org/x/net v0.0.0-20210913180222-943fd674d43e/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@ -491,6 +499,8 @@ golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c= golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 h1:y/woIyUBFbpQGKS0u1aHF/40WUDnek3fPOyD08H5Vng=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
@ -580,6 +590,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/zeromq/goczmq.v4 v4.1.0 h1:CE+FE81mGVs2aSlnbfLuS1oAwdcVywyMM2AC1g33imI=
gopkg.in/zeromq/goczmq.v4 v4.1.0/go.mod h1:h4IlfePEYMpFdywGr5gAwKhBBj+hiBl/nF4VoSE4k+0=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

View File

@ -44,6 +44,7 @@ func (cfg *Config) GetConfig() error {
cfg.DbParams.DbUsername = ipblsection.Key("username").MustString("username") cfg.DbParams.DbUsername = ipblsection.Key("username").MustString("username")
cfg.DbParams.DbPassword = ipblsection.Key("password").MustString("password") cfg.DbParams.DbPassword = ipblsection.Key("password").MustString("password")
cfg.DbParams.DbDatabase = ipblsection.Key("database").MustString("database") cfg.DbParams.DbDatabase = ipblsection.Key("database").MustString("database")
cfg.Options.ZMQChannel = "ipbl"
cfg.Options.HideBanner = ipblsection.Key("hidebanner").MustBool(false) cfg.Options.HideBanner = ipblsection.Key("hidebanner").MustBool(false)
return nil return nil
@ -60,6 +61,7 @@ type Config struct {
Options struct { Options struct {
Version string `json:"version"` Version string `json:"version"`
HideBanner bool `json:"hidebanner"` HideBanner bool `json:"hidebanner"`
ZMQChannel string `json:"zmqchannel"`
} `json:"-"` } `json:"-"`
Switchs struct { Switchs struct {
Port int `json:"port"` Port int `json:"port"`

View File

@ -138,10 +138,4 @@ func RegisterRoutes(e *echo.Echo, ctx *context.Context, cfg *config.Config) {
disc, err := models.DiscoverURLS(*cfg) disc, err := models.DiscoverURLS(*cfg)
return Result(c, err, disc) return Result(c, err, disc)
}) })
e.Logger.Fatal(
e.Start(
fmt.Sprintf(":%d",
cfg.Switchs.Port)))
} }

View File

@ -15,8 +15,10 @@ func RunServer(ctx *context.Context, cfg *config.Config) (err error) {
e.HideBanner = true e.HideBanner = true
RegisterRoutes(e, ctx, cfg) RegisterRoutes(e, ctx, cfg)
err = e.Start(
fmt.Sprintf(":%d",
cfg.Switchs.Port))
e.Logger.Fatal(e.Start(fmt.Sprintf(":%d", cfg.Switchs.Port)))
return return
} }

74
src/zmqrouter/main.go Normal file
View File

@ -0,0 +1,74 @@
package zmqrouter
import (
"encoding/json"
"fmt"
"log"
"git.paulbsd.com/paulbsd/ipbl/src/config"
"git.paulbsd.com/paulbsd/ipbl/src/models"
"gopkg.in/zeromq/goczmq.v4"
)
func Init(cfg *config.Config) (err error) {
log.Println("Initiating ZMQ sockets")
reqsock, err := InitRep()
if err != nil {
return
}
pubsock, err := InitPub()
if err != nil {
return
}
Handle(cfg, reqsock, pubsock, cfg.Options.ZMQChannel)
return
}
func Handle(cfg *config.Config, reqsock *goczmq.Sock, pubsock *goczmq.Sock, channel string) (err error) {
log.Println("Start handling zmq sockets")
for {
var msg = "err"
var req, err = reqsock.RecvMessage()
if err != nil {
log.Println("unable to receive message from req socket")
continue
}
var topub [][]byte
for _, val := range req {
var ip = models.IP{}
err = json.Unmarshal(val, &ip)
if err != nil {
log.Println("unable to parse ip address", err)
continue
}
has, err := cfg.Db.Get(&ip)
if err != nil {
log.Println("error fetching ip address", err)
continue
}
if !has {
num, err := cfg.Db.Insert(&ip)
if err != nil {
log.Println("error inserting ip address", num, err)
continue
}
}
tmpval := fmt.Sprintf("%s %s", channel, string(val))
val = []byte(tmpval)
topub = append(topub, val)
}
err = pubsock.SendMessage(topub)
if err != nil {
log.Println("error sending message to pub socket")
continue
}
msg = "ok"
var resp [][]byte = [][]byte{[]byte(msg)}
err = reqsock.SendMessage(resp)
if err != nil {
log.Println("error replying message to req socket")
continue
}
}
}

10
src/zmqrouter/pubsub.go Normal file
View File

@ -0,0 +1,10 @@
package zmqrouter
import (
"gopkg.in/zeromq/goczmq.v4"
)
func InitPub() (sock *goczmq.Sock, err error) {
sock, err = goczmq.NewPub("tcp://*:9999")
return
}

10
src/zmqrouter/reqrep.go Normal file
View File

@ -0,0 +1,10 @@
package zmqrouter
import (
"gopkg.in/zeromq/goczmq.v4"
)
func InitRep() (sock *goczmq.Sock, err error) {
sock, err = goczmq.NewRep("tcp://*:9998")
return
}

View File

@ -4,6 +4,7 @@ import (
"flag" "flag"
"log" "log"
"os" "os"
"time"
) )
// Usage displays possible arguments // Usage displays possible arguments
@ -20,3 +21,9 @@ func Advice(advice string) {
} }
os.Exit(0) os.Exit(0)
} }
func Server() {
for {
time.Sleep(time.Second)
}
}

View File

@ -1,5 +1,18 @@
# v0.9.5 - 2022/03/04
### Fix bugs
* Fix panic when decoding time.Time with context ( #328 )
* Fix reading the next character in buffer to nul consideration ( #338 )
* Fix incorrect handling on skipValue ( #341 )
### Improve decoder performance
* Improve performance when a payload contains escape sequence ( #334 )
# v0.9.4 - 2022/01/21 # v0.9.4 - 2022/01/21
* Fix IsNilForMarshaler for string type with omitempty ( #323 )
* Fix the case where the embedded field is at the end ( #326 ) * Fix the case where the embedded field is at the end ( #326 )
# v0.9.3 - 2022/01/14 # v0.9.3 - 2022/01/14

View File

@ -87,13 +87,13 @@ func (d *mapDecoder) DecodeStream(s *Stream, depth int64, p unsafe.Pointer) erro
if mapValue == nil { if mapValue == nil {
mapValue = makemap(d.mapType, 0) mapValue = makemap(d.mapType, 0)
} }
if s.buf[s.cursor+1] == '}' { s.cursor++
if s.equalChar('}') {
*(*unsafe.Pointer)(p) = mapValue *(*unsafe.Pointer)(p) = mapValue
s.cursor += 2 s.cursor++
return nil return nil
} }
for { for {
s.cursor++
k := unsafe_New(d.keyType) k := unsafe_New(d.keyType)
if err := d.keyDecoder.DecodeStream(s, depth, k); err != nil { if err := d.keyDecoder.DecodeStream(s, depth, k); err != nil {
return err return err
@ -117,6 +117,7 @@ func (d *mapDecoder) DecodeStream(s *Stream, depth int64, p unsafe.Pointer) erro
if !s.equalChar(',') { if !s.equalChar(',') {
return errors.ErrExpected("comma after object value", s.totalOffset()) return errors.ErrExpected("comma after object value", s.totalOffset())
} }
s.cursor++
} }
} }

View File

@ -423,7 +423,6 @@ func (s *Stream) skipValue(depth int64) error {
continue continue
} else if c == nul { } else if c == nul {
if s.read() { if s.read() {
s.cursor-- // for retry current character
_, cursor, p = s.stat() _, cursor, p = s.stat()
continue continue
} }

View File

@ -1,6 +1,7 @@
package decoder package decoder
import ( import (
"bytes"
"reflect" "reflect"
"unicode" "unicode"
"unicode/utf16" "unicode/utf16"
@ -308,49 +309,30 @@ func (d *stringDecoder) decodeByte(buf []byte, cursor int64) ([]byte, int64, err
cursor++ cursor++
start := cursor start := cursor
b := (*sliceHeader)(unsafe.Pointer(&buf)).data b := (*sliceHeader)(unsafe.Pointer(&buf)).data
escaped := 0
for { for {
switch char(b, cursor) { switch char(b, cursor) {
case '\\': case '\\':
escaped++
cursor++ cursor++
switch char(b, cursor) { switch char(b, cursor) {
case '"': case '"', '\\', '/', 'b', 'f', 'n', 'r', 't':
buf[cursor] = '"' cursor++
buf = append(buf[:cursor-1], buf[cursor:]...)
case '\\':
buf[cursor] = '\\'
buf = append(buf[:cursor-1], buf[cursor:]...)
case '/':
buf[cursor] = '/'
buf = append(buf[:cursor-1], buf[cursor:]...)
case 'b':
buf[cursor] = '\b'
buf = append(buf[:cursor-1], buf[cursor:]...)
case 'f':
buf[cursor] = '\f'
buf = append(buf[:cursor-1], buf[cursor:]...)
case 'n':
buf[cursor] = '\n'
buf = append(buf[:cursor-1], buf[cursor:]...)
case 'r':
buf[cursor] = '\r'
buf = append(buf[:cursor-1], buf[cursor:]...)
case 't':
buf[cursor] = '\t'
buf = append(buf[:cursor-1], buf[cursor:]...)
case 'u': case 'u':
buflen := int64(len(buf)) buflen := int64(len(buf))
if cursor+5 >= buflen { if cursor+5 >= buflen {
return nil, 0, errors.ErrUnexpectedEndOfJSON("escaped string", cursor) return nil, 0, errors.ErrUnexpectedEndOfJSON("escaped string", cursor)
} }
code := unicodeToRune(buf[cursor+1 : cursor+5]) cursor += 5
unicode := []byte(string(code))
buf = append(append(buf[:cursor-1], unicode...), buf[cursor+5:]...)
default: default:
return nil, 0, errors.ErrUnexpectedEndOfJSON("escaped string", cursor) return nil, 0, errors.ErrUnexpectedEndOfJSON("escaped string", cursor)
} }
continue continue
case '"': case '"':
literal := buf[start:cursor] literal := buf[start:cursor]
if escaped > 0 {
literal = literal[:unescapeString(literal, escaped)]
}
cursor++ cursor++
return literal, cursor, nil return literal, cursor, nil
case nul: case nul:
@ -369,3 +351,33 @@ func (d *stringDecoder) decodeByte(buf []byte, cursor int64) ([]byte, int64, err
} }
} }
} }
var unescapeMap = [256]byte{
'"': '"',
'\\': '\\',
'/': '/',
'b': '\b',
'f': '\f',
'n': '\n',
'r': '\r',
't': '\t',
}
func unescapeString(buf []byte, escaped int) int {
cursor := 0
for i := 0; i < escaped; i++ {
cursor += bytes.IndexByte(buf[cursor:], '\\')
c := buf[cursor+1]
if c == 'u' {
code := unicodeToRune(buf[cursor+2 : cursor+6])
unicode := []byte(string(code))
buf = append(append(buf[:cursor], unicode...), buf[cursor+6:]...)
cursor += len(unicode)
} else {
buf[cursor+1] = unescapeMap[c]
buf = append(buf[:cursor], buf[cursor+1:]...)
cursor++
}
}
return len(buf)
}

View File

@ -1,6 +1,7 @@
package decoder package decoder
import ( import (
"context"
"encoding/json" "encoding/json"
"unsafe" "unsafe"
@ -46,13 +47,20 @@ func (d *unmarshalJSONDecoder) DecodeStream(s *Stream, depth int64, p unsafe.Poi
typ: d.typ, typ: d.typ,
ptr: p, ptr: p,
})) }))
switch v := v.(type) {
case unmarshalerContext:
var ctx context.Context
if (s.Option.Flags & ContextOption) != 0 { if (s.Option.Flags & ContextOption) != 0 {
if err := v.(unmarshalerContext).UnmarshalJSON(s.Option.Context, dst); err != nil { ctx = s.Option.Context
} else {
ctx = context.Background()
}
if err := v.UnmarshalJSON(ctx, dst); err != nil {
d.annotateError(s.cursor, err) d.annotateError(s.cursor, err)
return err return err
} }
} else { case json.Unmarshaler:
if err := v.(json.Unmarshaler).UnmarshalJSON(dst); err != nil { if err := v.UnmarshalJSON(dst); err != nil {
d.annotateError(s.cursor, err) d.annotateError(s.cursor, err)
return err return err
} }

View File

@ -1,5 +1,26 @@
# Changelog # Changelog
## v4.7.0 - 2022-03-01
**Enhancements**
* Add JWT, KeyAuth, CSRF multivalue extractors [#2060](https://github.com/labstack/echo/pull/2060)
* Add LogErrorFunc to recover middleware [#2072](https://github.com/labstack/echo/pull/2072)
* Add support for HEAD method query params binding [#2027](https://github.com/labstack/echo/pull/2027)
* Improve filesystem support with echo.FileFS, echo.StaticFS, group.FileFS, group.StaticFS [#2064](https://github.com/labstack/echo/pull/2064)
**Fixes**
* Fix X-Real-IP bug, improve tests [#2007](https://github.com/labstack/echo/pull/2007)
* Minor syntax fixes [#1994](https://github.com/labstack/echo/pull/1994), [#2102](https://github.com/labstack/echo/pull/2102), [#2102](https://github.com/labstack/echo/pull/2102)
**General**
* Add cache-control and connection headers [#2103](https://github.com/labstack/echo/pull/2103)
* Add Retry-After header constant [#2078](https://github.com/labstack/echo/pull/2078)
* Upgrade `go` directive in `go.mod` to 1.17 [#2049](https://github.com/labstack/echo/pull/2049)
* Add Pagoda [#2077](https://github.com/labstack/echo/pull/2077) and Souin [#2069](https://github.com/labstack/echo/pull/2069) to 3rd-party middlewares in README
## v4.6.3 - 2022-01-10 ## v4.6.3 - 2022-01-10
**Fixes** **Fixes**

View File

@ -5,7 +5,6 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/labstack/echo?style=flat-square)](https://goreportcard.com/report/github.com/labstack/echo) [![Go Report Card](https://goreportcard.com/badge/github.com/labstack/echo?style=flat-square)](https://goreportcard.com/report/github.com/labstack/echo)
[![Build Status](http://img.shields.io/travis/labstack/echo.svg?style=flat-square)](https://travis-ci.org/labstack/echo) [![Build Status](http://img.shields.io/travis/labstack/echo.svg?style=flat-square)](https://travis-ci.org/labstack/echo)
[![Codecov](https://img.shields.io/codecov/c/github/labstack/echo.svg?style=flat-square)](https://codecov.io/gh/labstack/echo) [![Codecov](https://img.shields.io/codecov/c/github/labstack/echo.svg?style=flat-square)](https://codecov.io/gh/labstack/echo)
[![Join the chat at https://gitter.im/labstack/echo](https://img.shields.io/badge/gitter-join%20chat-brightgreen.svg?style=flat-square)](https://gitter.im/labstack/echo)
[![Forum](https://img.shields.io/badge/community-forum-00afd1.svg?style=flat-square)](https://github.com/labstack/echo/discussions) [![Forum](https://img.shields.io/badge/community-forum-00afd1.svg?style=flat-square)](https://github.com/labstack/echo/discussions)
[![Twitter](https://img.shields.io/badge/twitter-@labstack-55acee.svg?style=flat-square)](https://twitter.com/labstack) [![Twitter](https://img.shields.io/badge/twitter-@labstack-55acee.svg?style=flat-square)](https://twitter.com/labstack)
[![License](http://img.shields.io/badge/license-mit-blue.svg?style=flat-square)](https://raw.githubusercontent.com/labstack/echo/master/LICENSE) [![License](http://img.shields.io/badge/license-mit-blue.svg?style=flat-square)](https://raw.githubusercontent.com/labstack/echo/master/LICENSE)
@ -92,10 +91,23 @@ func hello(c echo.Context) error {
} }
``` ```
# Third-party middlewares
| Repository | Description |
|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [github.com/labstack/echo-contrib](https://github.com/labstack/echo-contrib) | (by Echo team) [casbin](https://github.com/casbin/casbin), [gorilla/sessions](https://github.com/gorilla/sessions), [jaegertracing](github.com/uber/jaeger-client-go), [prometheus](https://github.com/prometheus/client_golang/), [pprof](https://pkg.go.dev/net/http/pprof), [zipkin](https://github.com/openzipkin/zipkin-go) middlewares |
| [deepmap/oapi-codegen](https://github.com/deepmap/oapi-codegen) | Automatically generate RESTful API documentation with [OpenAPI](https://swagger.io/specification/) Client and Server Code Generator |
| [github.com/swaggo/echo-swagger](https://github.com/swaggo/echo-swagger) | Automatically generate RESTful API documentation with [Swagger](https://swagger.io/) 2.0. |
| [github.com/ziflex/lecho](https://github.com/ziflex/lecho) | [Zerolog](https://github.com/rs/zerolog) logging library wrapper for Echo logger interface. |
| [github.com/brpaz/echozap](https://github.com/brpaz/echozap) | Uber´s [Zap](https://github.com/uber-go/zap) logging library wrapper for Echo logger interface. |
| [github.com/darkweak/souin/plugins/echo](https://github.com/darkweak/souin/tree/master/plugins/echo) | HTTP cache system based on [Souin](https://github.com/darkweak/souin) to automatically get your endpoints cached. It supports some distributed and non-distributed storage systems depending your needs. |
| [github.com/mikestefanello/pagoda](https://github.com/mikestefanello/pagoda) | Rapid, easy full-stack web development starter kit built with Echo.
Please send a PR to add your own library here.
## Help ## Help
- [Forum](https://github.com/labstack/echo/discussions) - [Forum](https://github.com/labstack/echo/discussions)
- [Chat](https://gitter.im/labstack/echo)
## Contribute ## Contribute

View File

@ -111,11 +111,11 @@ func (b *DefaultBinder) Bind(i interface{}, c Context) (err error) {
if err := b.BindPathParams(c, i); err != nil { if err := b.BindPathParams(c, i); err != nil {
return err return err
} }
// Issue #1670 - Query params are binded only for GET/DELETE and NOT for usual request with body (POST/PUT/PATCH) // Only bind query parameters for GET/DELETE/HEAD to avoid unexpected behavior with destination struct binding from body.
// Reasoning here is that parameters in query and bind destination struct could have UNEXPECTED matches and results due that. // For example a request URL `&id=1&lang=en` with body `{"id":100,"lang":"de"}` would lead to precedence issues.
// i.e. is `&id=1&lang=en` from URL same as `{"id":100,"lang":"de"}` request body and which one should have priority when binding. // The HTTP method check restores pre-v4.1.11 behavior to avoid these problems (see issue #1670)
// This HTTP method check restores pre v4.1.11 behavior and avoids different problems when query is mixed with body method := c.Request().Method
if c.Request().Method == http.MethodGet || c.Request().Method == http.MethodDelete { if method == http.MethodGet || method == http.MethodDelete || method == http.MethodHead {
if err = b.BindQueryParams(c, i); err != nil { if err = b.BindQueryParams(c, i); err != nil {
return err return err
} }

View File

@ -9,8 +9,6 @@ import (
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
"os"
"path/filepath"
"strings" "strings"
"sync" "sync"
) )
@ -210,6 +208,13 @@ type (
} }
) )
const (
// ContextKeyHeaderAllow is set by Router for getting value for `Allow` header in later stages of handler call chain.
// Allow header is mandatory for status 405 (method not found) and useful for OPTIONS method requests.
// It is added to context only when Router does not find matching method handler for request.
ContextKeyHeaderAllow = "echo_header_allow"
)
const ( const (
defaultMemory = 32 << 20 // 32 MB defaultMemory = 32 << 20 // 32 MB
indexPage = "index.html" indexPage = "index.html"
@ -562,29 +567,6 @@ func (c *context) Stream(code int, contentType string, r io.Reader) (err error)
return return
} }
func (c *context) File(file string) (err error) {
f, err := os.Open(file)
if err != nil {
return NotFoundHandler(c)
}
defer f.Close()
fi, _ := f.Stat()
if fi.IsDir() {
file = filepath.Join(file, indexPage)
f, err = os.Open(file)
if err != nil {
return NotFoundHandler(c)
}
defer f.Close()
if fi, err = f.Stat(); err != nil {
return
}
}
http.ServeContent(c.Response(), c.Request(), fi.Name(), fi.ModTime(), f)
return
}
func (c *context) Attachment(file, name string) error { func (c *context) Attachment(file, name string) error {
return c.contentDisposition(file, name, "attachment") return c.contentDisposition(file, name, "attachment")
} }

33
vendor/github.com/labstack/echo/v4/context_fs.go generated vendored Normal file
View File

@ -0,0 +1,33 @@
//go:build !go1.16
// +build !go1.16
package echo
import (
"net/http"
"os"
"path/filepath"
)
func (c *context) File(file string) (err error) {
f, err := os.Open(file)
if err != nil {
return NotFoundHandler(c)
}
defer f.Close()
fi, _ := f.Stat()
if fi.IsDir() {
file = filepath.Join(file, indexPage)
f, err = os.Open(file)
if err != nil {
return NotFoundHandler(c)
}
defer f.Close()
if fi, err = f.Stat(); err != nil {
return
}
}
http.ServeContent(c.Response(), c.Request(), fi.Name(), fi.ModTime(), f)
return
}

View File

@ -0,0 +1,52 @@
//go:build go1.16
// +build go1.16
package echo
import (
"errors"
"io"
"io/fs"
"net/http"
"path/filepath"
)
func (c *context) File(file string) error {
return fsFile(c, file, c.echo.Filesystem)
}
// FileFS serves file from given file system.
//
// When dealing with `embed.FS` use `fs := echo.MustSubFS(fs, "rootDirectory") to create sub fs which uses necessary
// prefix for directory path. This is necessary as `//go:embed assets/images` embeds files with paths
// including `assets/images` as their prefix.
func (c *context) FileFS(file string, filesystem fs.FS) error {
return fsFile(c, file, filesystem)
}
func fsFile(c Context, file string, filesystem fs.FS) error {
f, err := filesystem.Open(file)
if err != nil {
return ErrNotFound
}
defer f.Close()
fi, _ := f.Stat()
if fi.IsDir() {
file = filepath.ToSlash(filepath.Join(file, indexPage)) // ToSlash is necessary for Windows. fs.Open and os.Open are different in that aspect.
f, err = filesystem.Open(file)
if err != nil {
return ErrNotFound
}
defer f.Close()
if fi, err = f.Stat(); err != nil {
return err
}
}
ff, ok := f.(io.ReadSeeker)
if !ok {
return errors.New("file does not implement io.ReadSeeker")
}
http.ServeContent(c.Response(), c.Request(), fi.Name(), fi.ModTime(), ff)
return nil
}

View File

@ -47,9 +47,6 @@ import (
stdLog "log" stdLog "log"
"net" "net"
"net/http" "net/http"
"net/url"
"os"
"path/filepath"
"reflect" "reflect"
"runtime" "runtime"
"sync" "sync"
@ -66,6 +63,7 @@ import (
type ( type (
// Echo is the top-level framework instance. // Echo is the top-level framework instance.
Echo struct { Echo struct {
filesystem
common common
// startupMutex is mutex to lock Echo instance access during server configuration and startup. Useful for to get // startupMutex is mutex to lock Echo instance access during server configuration and startup. Useful for to get
// listener address info (on which interface/port was listener binded) without having data races. // listener address info (on which interface/port was listener binded) without having data races.
@ -77,7 +75,6 @@ type (
maxParam *int maxParam *int
router *Router router *Router
routers map[string]*Router routers map[string]*Router
notFoundHandler HandlerFunc
pool sync.Pool pool sync.Pool
Server *http.Server Server *http.Server
TLSServer *http.Server TLSServer *http.Server
@ -113,10 +110,10 @@ type (
} }
// MiddlewareFunc defines a function to process middleware. // MiddlewareFunc defines a function to process middleware.
MiddlewareFunc func(HandlerFunc) HandlerFunc MiddlewareFunc func(next HandlerFunc) HandlerFunc
// HandlerFunc defines a function to serve HTTP requests. // HandlerFunc defines a function to serve HTTP requests.
HandlerFunc func(Context) error HandlerFunc func(c Context) error
// HTTPErrorHandler is a centralized HTTP error handler. // HTTPErrorHandler is a centralized HTTP error handler.
HTTPErrorHandler func(error, Context) HTTPErrorHandler func(error, Context)
@ -192,6 +189,10 @@ const (
const ( const (
HeaderAccept = "Accept" HeaderAccept = "Accept"
HeaderAcceptEncoding = "Accept-Encoding" HeaderAcceptEncoding = "Accept-Encoding"
// HeaderAllow is the name of the "Allow" header field used to list the set of methods
// advertised as supported by the target resource. Returning an Allow header is mandatory
// for status 405 (method not found) and useful for the OPTIONS method in responses.
// See RFC 7231: https://datatracker.ietf.org/doc/html/rfc7231#section-7.4.1
HeaderAllow = "Allow" HeaderAllow = "Allow"
HeaderAuthorization = "Authorization" HeaderAuthorization = "Authorization"
HeaderContentDisposition = "Content-Disposition" HeaderContentDisposition = "Content-Disposition"
@ -203,6 +204,7 @@ const (
HeaderIfModifiedSince = "If-Modified-Since" HeaderIfModifiedSince = "If-Modified-Since"
HeaderLastModified = "Last-Modified" HeaderLastModified = "Last-Modified"
HeaderLocation = "Location" HeaderLocation = "Location"
HeaderRetryAfter = "Retry-After"
HeaderUpgrade = "Upgrade" HeaderUpgrade = "Upgrade"
HeaderVary = "Vary" HeaderVary = "Vary"
HeaderWWWAuthenticate = "WWW-Authenticate" HeaderWWWAuthenticate = "WWW-Authenticate"
@ -212,12 +214,14 @@ const (
HeaderXForwardedSsl = "X-Forwarded-Ssl" HeaderXForwardedSsl = "X-Forwarded-Ssl"
HeaderXUrlScheme = "X-Url-Scheme" HeaderXUrlScheme = "X-Url-Scheme"
HeaderXHTTPMethodOverride = "X-HTTP-Method-Override" HeaderXHTTPMethodOverride = "X-HTTP-Method-Override"
HeaderXRealIP = "X-Real-IP" HeaderXRealIP = "X-Real-Ip"
HeaderXRequestID = "X-Request-ID" HeaderXRequestID = "X-Request-Id"
HeaderXCorrelationID = "X-Correlation-ID" HeaderXCorrelationID = "X-Correlation-Id"
HeaderXRequestedWith = "X-Requested-With" HeaderXRequestedWith = "X-Requested-With"
HeaderServer = "Server" HeaderServer = "Server"
HeaderOrigin = "Origin" HeaderOrigin = "Origin"
HeaderCacheControl = "Cache-Control"
HeaderConnection = "Connection"
// Access control // Access control
HeaderAccessControlRequestMethod = "Access-Control-Request-Method" HeaderAccessControlRequestMethod = "Access-Control-Request-Method"
@ -242,7 +246,7 @@ const (
const ( const (
// Version of Echo // Version of Echo
Version = "4.6.3" Version = "4.7.0"
website = "https://echo.labstack.com" website = "https://echo.labstack.com"
// http://patorjk.com/software/taag/#p=display&f=Small%20Slant&t=Echo // http://patorjk.com/software/taag/#p=display&f=Small%20Slant&t=Echo
banner = ` banner = `
@ -302,6 +306,12 @@ var (
} }
MethodNotAllowedHandler = func(c Context) error { MethodNotAllowedHandler = func(c Context) error {
// See RFC 7231 section 7.4.1: An origin server MUST generate an Allow field in a 405 (Method Not Allowed)
// response and MAY do so in any other response. For disabled resources an empty Allow header may be returned
routerAllowMethods, ok := c.Get(ContextKeyHeaderAllow).(string)
if ok && routerAllowMethods != "" {
c.Response().Header().Set(HeaderAllow, routerAllowMethods)
}
return ErrMethodNotAllowed return ErrMethodNotAllowed
} }
) )
@ -309,6 +319,7 @@ var (
// New creates an instance of Echo. // New creates an instance of Echo.
func New() (e *Echo) { func New() (e *Echo) {
e = &Echo{ e = &Echo{
filesystem: createFilesystem(),
Server: new(http.Server), Server: new(http.Server),
TLSServer: new(http.Server), TLSServer: new(http.Server),
AutoTLSManager: autocert.Manager{ AutoTLSManager: autocert.Manager{
@ -489,50 +500,6 @@ func (e *Echo) Match(methods []string, path string, handler HandlerFunc, middlew
return routes return routes
} }
// Static registers a new route with path prefix to serve static files from the
// provided root directory.
func (e *Echo) Static(prefix, root string) *Route {
if root == "" {
root = "." // For security we want to restrict to CWD.
}
return e.static(prefix, root, e.GET)
}
func (common) static(prefix, root string, get func(string, HandlerFunc, ...MiddlewareFunc) *Route) *Route {
h := func(c Context) error {
p, err := url.PathUnescape(c.Param("*"))
if err != nil {
return err
}
name := filepath.Join(root, filepath.Clean("/"+p)) // "/"+ for security
fi, err := os.Stat(name)
if err != nil {
// The access path does not exist
return NotFoundHandler(c)
}
// If the request is for a directory and does not end with "/"
p = c.Request().URL.Path // path must not be empty.
if fi.IsDir() && p[len(p)-1] != '/' {
// Redirect to ends with "/"
return c.Redirect(http.StatusMovedPermanently, p+"/")
}
return c.File(name)
}
// Handle added routes based on trailing slash:
// /prefix => exact route "/prefix" + any route "/prefix/*"
// /prefix/ => only any route "/prefix/*"
if prefix != "" {
if prefix[len(prefix)-1] == '/' {
// Only add any route for intentional trailing slash
return get(prefix+"*", h)
}
get(prefix, h)
}
return get(prefix+"/*", h)
}
func (common) file(path, file string, get func(string, HandlerFunc, ...MiddlewareFunc) *Route, func (common) file(path, file string, get func(string, HandlerFunc, ...MiddlewareFunc) *Route,
m ...MiddlewareFunc) *Route { m ...MiddlewareFunc) *Route {
return get(path, func(c Context) error { return get(path, func(c Context) error {
@ -643,7 +610,7 @@ func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Acquire context // Acquire context
c := e.pool.Get().(*context) c := e.pool.Get().(*context)
c.Reset(r, w) c.Reset(r, w)
h := NotFoundHandler var h func(Context) error
if e.premiddleware == nil { if e.premiddleware == nil {
e.findRouter(r.Host).Find(r.Method, GetPath(r), c) e.findRouter(r.Host).Find(r.Method, GetPath(r), c)

62
vendor/github.com/labstack/echo/v4/echo_fs.go generated vendored Normal file
View File

@ -0,0 +1,62 @@
//go:build !go1.16
// +build !go1.16
package echo
import (
"net/http"
"net/url"
"os"
"path/filepath"
)
type filesystem struct {
}
func createFilesystem() filesystem {
return filesystem{}
}
// Static registers a new route with path prefix to serve static files from the
// provided root directory.
func (e *Echo) Static(prefix, root string) *Route {
if root == "" {
root = "." // For security we want to restrict to CWD.
}
return e.static(prefix, root, e.GET)
}
func (common) static(prefix, root string, get func(string, HandlerFunc, ...MiddlewareFunc) *Route) *Route {
h := func(c Context) error {
p, err := url.PathUnescape(c.Param("*"))
if err != nil {
return err
}
name := filepath.Join(root, filepath.Clean("/"+p)) // "/"+ for security
fi, err := os.Stat(name)
if err != nil {
// The access path does not exist
return NotFoundHandler(c)
}
// If the request is for a directory and does not end with "/"
p = c.Request().URL.Path // path must not be empty.
if fi.IsDir() && p[len(p)-1] != '/' {
// Redirect to ends with "/"
return c.Redirect(http.StatusMovedPermanently, p+"/")
}
return c.File(name)
}
// Handle added routes based on trailing slash:
// /prefix => exact route "/prefix" + any route "/prefix/*"
// /prefix/ => only any route "/prefix/*"
if prefix != "" {
if prefix[len(prefix)-1] == '/' {
// Only add any route for intentional trailing slash
return get(prefix+"*", h)
}
get(prefix, h)
}
return get(prefix+"/*", h)
}

145
vendor/github.com/labstack/echo/v4/echo_fs_go1.16.go generated vendored Normal file
View File

@ -0,0 +1,145 @@
//go:build go1.16
// +build go1.16
package echo
import (
"fmt"
"io/fs"
"net/http"
"net/url"
"os"
"path/filepath"
"strings"
)
type filesystem struct {
// Filesystem is file system used by Static and File handlers to access files.
// Defaults to os.DirFS(".")
//
// When dealing with `embed.FS` use `fs := echo.MustSubFS(fs, "rootDirectory") to create sub fs which uses necessary
// prefix for directory path. This is necessary as `//go:embed assets/images` embeds files with paths
// including `assets/images` as their prefix.
Filesystem fs.FS
}
func createFilesystem() filesystem {
return filesystem{
Filesystem: newDefaultFS(),
}
}
// Static registers a new route with path prefix to serve static files from the provided root directory.
func (e *Echo) Static(pathPrefix, fsRoot string) *Route {
subFs := MustSubFS(e.Filesystem, fsRoot)
return e.Add(
http.MethodGet,
pathPrefix+"*",
StaticDirectoryHandler(subFs, false),
)
}
// StaticFS registers a new route with path prefix to serve static files from the provided file system.
//
// When dealing with `embed.FS` use `fs := echo.MustSubFS(fs, "rootDirectory") to create sub fs which uses necessary
// prefix for directory path. This is necessary as `//go:embed assets/images` embeds files with paths
// including `assets/images` as their prefix.
func (e *Echo) StaticFS(pathPrefix string, filesystem fs.FS) *Route {
return e.Add(
http.MethodGet,
pathPrefix+"*",
StaticDirectoryHandler(filesystem, false),
)
}
// StaticDirectoryHandler creates handler function to serve files from provided file system
// When disablePathUnescaping is set then file name from path is not unescaped and is served as is.
func StaticDirectoryHandler(fileSystem fs.FS, disablePathUnescaping bool) HandlerFunc {
return func(c Context) error {
p := c.Param("*")
if !disablePathUnescaping { // when router is already unescaping we do not want to do is twice
tmpPath, err := url.PathUnescape(p)
if err != nil {
return fmt.Errorf("failed to unescape path variable: %w", err)
}
p = tmpPath
}
// fs.FS.Open() already assumes that file names are relative to FS root path and considers name with prefix `/` as invalid
name := filepath.ToSlash(filepath.Clean(strings.TrimPrefix(p, "/")))
fi, err := fs.Stat(fileSystem, name)
if err != nil {
return ErrNotFound
}
// If the request is for a directory and does not end with "/"
p = c.Request().URL.Path // path must not be empty.
if fi.IsDir() && len(p) > 0 && p[len(p)-1] != '/' {
// Redirect to ends with "/"
return c.Redirect(http.StatusMovedPermanently, p+"/")
}
return fsFile(c, name, fileSystem)
}
}
// FileFS registers a new route with path to serve file from the provided file system.
func (e *Echo) FileFS(path, file string, filesystem fs.FS, m ...MiddlewareFunc) *Route {
return e.GET(path, StaticFileHandler(file, filesystem), m...)
}
// StaticFileHandler creates handler function to serve file from provided file system
func StaticFileHandler(file string, filesystem fs.FS) HandlerFunc {
return func(c Context) error {
return fsFile(c, file, filesystem)
}
}
// defaultFS emulates os.Open behaviour with filesystem opened by `os.DirFs`. Difference between `os.Open` and `fs.Open`
// is that FS does not allow to open path that start with `..` or `/` etc. For example previously you could have `../images`
// in your application but `fs := os.DirFS("./")` would not allow you to use `fs.Open("../images")` and this would break
// all old applications that rely on being able to traverse up from current executable run path.
// NB: private because you really should use fs.FS implementation instances
type defaultFS struct {
prefix string
fs fs.FS
}
func newDefaultFS() *defaultFS {
dir, _ := os.Getwd()
return &defaultFS{
prefix: dir,
fs: os.DirFS(dir),
}
}
func (fs defaultFS) Open(name string) (fs.File, error) {
return fs.fs.Open(name)
}
func subFS(currentFs fs.FS, root string) (fs.FS, error) {
root = filepath.ToSlash(filepath.Clean(root)) // note: fs.FS operates only with slashes. `ToSlash` is necessary for Windows
if dFS, ok := currentFs.(*defaultFS); ok {
// we need to make exception for `defaultFS` instances as it interprets root prefix differently from fs.FS to
// allow cases when root is given as `../somepath` which is not valid for fs.FS
root = filepath.Join(dFS.prefix, root)
return &defaultFS{
prefix: root,
fs: os.DirFS(root),
}, nil
}
return fs.Sub(currentFs, root)
}
// MustSubFS creates sub FS from current filesystem or panic on failure.
// Panic happens when `fsRoot` contains invalid path according to `fs.ValidPath` rules.
//
// MustSubFS is helpful when dealing with `embed.FS` because for example `//go:embed assets/images` embeds files with
// paths including `assets/images` as their prefix. In that case use `fs := echo.MustSubFS(fs, "rootDirectory") to
// create sub fs which uses necessary prefix for directory path.
func MustSubFS(currentFs fs.FS, fsRoot string) fs.FS {
subFs, err := subFS(currentFs, fsRoot)
if err != nil {
panic(fmt.Errorf("can not create sub FS, invalid root given, err: %w", err))
}
return subFs
}

View File

@ -102,11 +102,6 @@ func (g *Group) Group(prefix string, middleware ...MiddlewareFunc) (sg *Group) {
return return
} }
// Static implements `Echo#Static()` for sub-routes within the Group.
func (g *Group) Static(prefix, root string) {
g.static(prefix, root, g.GET)
}
// File implements `Echo#File()` for sub-routes within the Group. // File implements `Echo#File()` for sub-routes within the Group.
func (g *Group) File(path, file string) { func (g *Group) File(path, file string) {
g.file(path, file, g.GET) g.file(path, file, g.GET)

9
vendor/github.com/labstack/echo/v4/group_fs.go generated vendored Normal file
View File

@ -0,0 +1,9 @@
//go:build !go1.16
// +build !go1.16
package echo
// Static implements `Echo#Static()` for sub-routes within the Group.
func (g *Group) Static(prefix, root string) {
g.static(prefix, root, g.GET)
}

33
vendor/github.com/labstack/echo/v4/group_fs_go1.16.go generated vendored Normal file
View File

@ -0,0 +1,33 @@
//go:build go1.16
// +build go1.16
package echo
import (
"io/fs"
"net/http"
)
// Static implements `Echo#Static()` for sub-routes within the Group.
func (g *Group) Static(pathPrefix, fsRoot string) {
subFs := MustSubFS(g.echo.Filesystem, fsRoot)
g.StaticFS(pathPrefix, subFs)
}
// StaticFS implements `Echo#StaticFS()` for sub-routes within the Group.
//
// When dealing with `embed.FS` use `fs := echo.MustSubFS(fs, "rootDirectory") to create sub fs which uses necessary
// prefix for directory path. This is necessary as `//go:embed assets/images` embeds files with paths
// including `assets/images` as their prefix.
func (g *Group) StaticFS(pathPrefix string, filesystem fs.FS) {
g.Add(
http.MethodGet,
pathPrefix+"*",
StaticDirectoryHandler(filesystem, false),
)
}
// FileFS implements `Echo#FileFS()` for sub-routes within the Group.
func (g *Group) FileFS(path, file string, filesystem fs.FS, m ...MiddlewareFunc) *Route {
return g.GET(path, StaticFileHandler(file, filesystem), m...)
}

View File

@ -6,6 +6,130 @@ import (
"strings" "strings"
) )
/**
By: https://github.com/tmshn (See: https://github.com/labstack/echo/pull/1478 , https://github.com/labstack/echox/pull/134 )
Source: https://echo.labstack.com/guide/ip-address/
IP address plays fundamental role in HTTP; it's used for access control, auditing, geo-based access analysis and more.
Echo provides handy method [`Context#RealIP()`](https://godoc.org/github.com/labstack/echo#Context) for that.
However, it is not trivial to retrieve the _real_ IP address from requests especially when you put L7 proxies before the application.
In such situation, _real_ IP needs to be relayed on HTTP layer from proxies to your app, but you must not trust HTTP headers unconditionally.
Otherwise, you might give someone a chance of deceiving you. **A security risk!**
To retrieve IP address reliably/securely, you must let your application be aware of the entire architecture of your infrastructure.
In Echo, this can be done by configuring `Echo#IPExtractor` appropriately.
This guides show you why and how.
> Note: if you dont' set `Echo#IPExtractor` explicitly, Echo fallback to legacy behavior, which is not a good choice.
Let's start from two questions to know the right direction:
1. Do you put any HTTP (L7) proxy in front of the application?
- It includes both cloud solutions (such as AWS ALB or GCP HTTP LB) and OSS ones (such as Nginx, Envoy or Istio ingress gateway).
2. If yes, what HTTP header do your proxies use to pass client IP to the application?
## Case 1. With no proxy
If you put no proxy (e.g.: directory facing to the internet), all you need to (and have to) see is IP address from network layer.
Any HTTP header is untrustable because the clients have full control what headers to be set.
In this case, use `echo.ExtractIPDirect()`.
```go
e.IPExtractor = echo.ExtractIPDirect()
```
## Case 2. With proxies using `X-Forwarded-For` header
[`X-Forwared-For` (XFF)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For) is the popular header
to relay clients' IP addresses.
At each hop on the proxies, they append the request IP address at the end of the header.
Following example diagram illustrates this behavior.
```text
"Origin" > Proxy 1 > Proxy 2 > Your app
(IP: a) (IP: b) (IP: c)
Case 1.
XFF: "" "a" "a, b"
~~~~~~
Case 2.
XFF: "x" "x, a" "x, a, b"
~~~~~~~~~
What your app will see
```
In this case, use **first _untrustable_ IP reading from right**. Never use first one reading from left, as it is
configurable by client. Here "trustable" means "you are sure the IP address belongs to your infrastructre".
In above example, if `b` and `c` are trustable, the IP address of the client is `a` for both cases, never be `x`.
In Echo, use `ExtractIPFromXFFHeader(...TrustOption)`.
```go
e.IPExtractor = echo.ExtractIPFromXFFHeader()
```
By default, it trusts internal IP addresses (loopback, link-local unicast, private-use and unique local address
from [RFC6890](https://tools.ietf.org/html/rfc6890), [RFC4291](https://tools.ietf.org/html/rfc4291) and
[RFC4193](https://tools.ietf.org/html/rfc4193)).
To control this behavior, use [`TrustOption`](https://godoc.org/github.com/labstack/echo#TrustOption)s.
E.g.:
```go
e.IPExtractor = echo.ExtractIPFromXFFHeader(
TrustLinkLocal(false),
TrustIPRanges(lbIPRange),
)
```
- Ref: https://godoc.org/github.com/labstack/echo#TrustOption
## Case 3. With proxies using `X-Real-IP` header
`X-Real-IP` is another HTTP header to relay clients' IP addresses, but it carries only one address unlike XFF.
If your proxies set this header, use `ExtractIPFromRealIPHeader(...TrustOption)`.
```go
e.IPExtractor = echo.ExtractIPFromRealIPHeader()
```
Again, it trusts internal IP addresses by default (loopback, link-local unicast, private-use and unique local address
from [RFC6890](https://tools.ietf.org/html/rfc6890), [RFC4291](https://tools.ietf.org/html/rfc4291) and
[RFC4193](https://tools.ietf.org/html/rfc4193)).
To control this behavior, use [`TrustOption`](https://godoc.org/github.com/labstack/echo#TrustOption)s.
- Ref: https://godoc.org/github.com/labstack/echo#TrustOption
> **Never forget** to configure the outermost proxy (i.e.; at the edge of your infrastructure) **not to pass through incoming headers**.
> Otherwise there is a chance of fraud, as it is what clients can control.
## About default behavior
In default behavior, Echo sees all of first XFF header, X-Real-IP header and IP from network layer.
As you might already notice, after reading this article, this is not good.
Sole reason this is default is just backward compatibility.
## Private IP ranges
See: https://en.wikipedia.org/wiki/Private_network
Private IPv4 address ranges (RFC 1918):
* 10.0.0.0 10.255.255.255 (24-bit block)
* 172.16.0.0 172.31.255.255 (20-bit block)
* 192.168.0.0 192.168.255.255 (16-bit block)
Private IPv6 address ranges:
* fc00::/7 address block = RFC 4193 Unique Local Addresses (ULA)
*/
type ipChecker struct { type ipChecker struct {
trustLoopback bool trustLoopback bool
trustLinkLocal bool trustLinkLocal bool
@ -52,6 +176,7 @@ func newIPChecker(configs []TrustOption) *ipChecker {
return checker return checker
} }
// Go1.16+ added `ip.IsPrivate()` but until that use this implementation
func isPrivateIPRange(ip net.IP) bool { func isPrivateIPRange(ip net.IP) bool {
if ip4 := ip.To4(); ip4 != nil { if ip4 := ip.To4(); ip4 != nil {
return ip4[0] == 10 || return ip4[0] == 10 ||
@ -87,10 +212,12 @@ type IPExtractor func(*http.Request) string
// ExtractIPDirect extracts IP address using actual IP address. // ExtractIPDirect extracts IP address using actual IP address.
// Use this if your server faces to internet directory (i.e.: uses no proxy). // Use this if your server faces to internet directory (i.e.: uses no proxy).
func ExtractIPDirect() IPExtractor { func ExtractIPDirect() IPExtractor {
return func(req *http.Request) string { return extractIP
}
func extractIP(req *http.Request) string {
ra, _, _ := net.SplitHostPort(req.RemoteAddr) ra, _, _ := net.SplitHostPort(req.RemoteAddr)
return ra return ra
}
} }
// ExtractIPFromRealIPHeader extracts IP address using x-real-ip header. // ExtractIPFromRealIPHeader extracts IP address using x-real-ip header.
@ -98,14 +225,13 @@ func ExtractIPDirect() IPExtractor {
func ExtractIPFromRealIPHeader(options ...TrustOption) IPExtractor { func ExtractIPFromRealIPHeader(options ...TrustOption) IPExtractor {
checker := newIPChecker(options) checker := newIPChecker(options)
return func(req *http.Request) string { return func(req *http.Request) string {
directIP := ExtractIPDirect()(req)
realIP := req.Header.Get(HeaderXRealIP) realIP := req.Header.Get(HeaderXRealIP)
if realIP != "" { if realIP != "" {
if ip := net.ParseIP(directIP); ip != nil && checker.trust(ip) { if ip := net.ParseIP(realIP); ip != nil && checker.trust(ip) {
return realIP return realIP
} }
} }
return directIP return extractIP(req)
} }
} }
@ -115,7 +241,7 @@ func ExtractIPFromRealIPHeader(options ...TrustOption) IPExtractor {
func ExtractIPFromXFFHeader(options ...TrustOption) IPExtractor { func ExtractIPFromXFFHeader(options ...TrustOption) IPExtractor {
checker := newIPChecker(options) checker := newIPChecker(options)
return func(req *http.Request) string { return func(req *http.Request) string {
directIP := ExtractIPDirect()(req) directIP := extractIP(req)
xffs := req.Header[HeaderXForwardedFor] xffs := req.Header[HeaderXForwardedFor]
if len(xffs) == 0 { if len(xffs) == 0 {
return directIP return directIP

View File

@ -1,6 +1,7 @@
package echo package echo
import ( import (
"bytes"
"net/http" "net/http"
) )
@ -42,6 +43,7 @@ type (
put HandlerFunc put HandlerFunc
trace HandlerFunc trace HandlerFunc
report HandlerFunc report HandlerFunc
allowHeader string
} }
) )
@ -68,6 +70,51 @@ func (m *methodHandler) isHandler() bool {
m.report != nil m.report != nil
} }
func (m *methodHandler) updateAllowHeader() {
buf := new(bytes.Buffer)
buf.WriteString(http.MethodOptions)
if m.connect != nil {
buf.WriteString(", ")
buf.WriteString(http.MethodConnect)
}
if m.delete != nil {
buf.WriteString(", ")
buf.WriteString(http.MethodDelete)
}
if m.get != nil {
buf.WriteString(", ")
buf.WriteString(http.MethodGet)
}
if m.head != nil {
buf.WriteString(", ")
buf.WriteString(http.MethodHead)
}
if m.patch != nil {
buf.WriteString(", ")
buf.WriteString(http.MethodPatch)
}
if m.post != nil {
buf.WriteString(", ")
buf.WriteString(http.MethodPost)
}
if m.propfind != nil {
buf.WriteString(", PROPFIND")
}
if m.put != nil {
buf.WriteString(", ")
buf.WriteString(http.MethodPut)
}
if m.trace != nil {
buf.WriteString(", ")
buf.WriteString(http.MethodTrace)
}
if m.report != nil {
buf.WriteString(", REPORT")
}
m.allowHeader = buf.String()
}
// NewRouter returns a new Router instance. // NewRouter returns a new Router instance.
func NewRouter(e *Echo) *Router { func NewRouter(e *Echo) *Router {
return &Router{ return &Router{
@ -326,6 +373,7 @@ func (n *node) addHandler(method string, h HandlerFunc) {
n.methodHandler.report = h n.methodHandler.report = h
} }
n.methodHandler.updateAllowHeader()
if h != nil { if h != nil {
n.isHandler = true n.isHandler = true
} else { } else {
@ -362,13 +410,14 @@ func (n *node) findHandler(method string) HandlerFunc {
} }
} }
func (n *node) checkMethodNotAllowed() HandlerFunc { func optionsMethodHandler(allowMethods string) func(c Context) error {
for _, m := range methods { return func(c Context) error {
if h := n.findHandler(m); h != nil { // Note: we are not handling most of the CORS headers here. CORS is handled by CORS middleware
return MethodNotAllowedHandler // 'OPTIONS' method RFC: https://httpwg.org/specs/rfc7231.html#OPTIONS
// 'Allow' header RFC: https://datatracker.ietf.org/doc/html/rfc7231#section-7.4.1
c.Response().Header().Add(HeaderAllow, allowMethods)
return c.NoContent(http.StatusNoContent)
} }
}
return NotFoundHandler
} }
// Find lookup a handler registered for method and path. It also parses URL for path // Find lookup a handler registered for method and path. It also parses URL for path
@ -563,10 +612,16 @@ func (r *Router) Find(method, path string, c Context) {
// use previous match as basis. although we have no matching handler we have path match. // use previous match as basis. although we have no matching handler we have path match.
// so we can send http.StatusMethodNotAllowed (405) instead of http.StatusNotFound (404) // so we can send http.StatusMethodNotAllowed (405) instead of http.StatusNotFound (404)
currentNode = previousBestMatchNode currentNode = previousBestMatchNode
ctx.handler = currentNode.checkMethodNotAllowed()
ctx.handler = NotFoundHandler
if currentNode.isHandler {
ctx.Set(ContextKeyHeaderAllow, currentNode.methodHandler.allowHeader)
ctx.handler = MethodNotAllowedHandler
if method == http.MethodOptions {
ctx.handler = optionsMethodHandler(currentNode.methodHandler.allowHeader)
}
}
} }
ctx.path = currentNode.ppath ctx.path = currentNode.ppath
ctx.pnames = currentNode.pnames ctx.pnames = currentNode.pnames
return
} }

17
vendor/golang.org/x/net/http2/go118.go generated vendored Normal file
View File

@ -0,0 +1,17 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.18
// +build go1.18
package http2
import (
"crypto/tls"
"net"
)
func tlsUnderlyingConn(tc *tls.Conn) net.Conn {
return tc.NetConn()
}

17
vendor/golang.org/x/net/http2/not_go118.go generated vendored Normal file
View File

@ -0,0 +1,17 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !go1.18
// +build !go1.18
package http2
import (
"crypto/tls"
"net"
)
func tlsUnderlyingConn(tc *tls.Conn) net.Conn {
return nil
}

View File

@ -735,7 +735,6 @@ func (cc *ClientConn) healthCheck() {
err := cc.Ping(ctx) err := cc.Ping(ctx)
if err != nil { if err != nil {
cc.closeForLostPing() cc.closeForLostPing()
cc.t.connPool().MarkDead(cc)
return return
} }
} }
@ -907,6 +906,24 @@ func (cc *ClientConn) onIdleTimeout() {
cc.closeIfIdle() cc.closeIfIdle()
} }
func (cc *ClientConn) closeConn() error {
t := time.AfterFunc(250*time.Millisecond, cc.forceCloseConn)
defer t.Stop()
return cc.tconn.Close()
}
// A tls.Conn.Close can hang for a long time if the peer is unresponsive.
// Try to shut it down more aggressively.
func (cc *ClientConn) forceCloseConn() {
tc, ok := cc.tconn.(*tls.Conn)
if !ok {
return
}
if nc := tlsUnderlyingConn(tc); nc != nil {
nc.Close()
}
}
func (cc *ClientConn) closeIfIdle() { func (cc *ClientConn) closeIfIdle() {
cc.mu.Lock() cc.mu.Lock()
if len(cc.streams) > 0 || cc.streamsReserved > 0 { if len(cc.streams) > 0 || cc.streamsReserved > 0 {
@ -921,7 +938,7 @@ func (cc *ClientConn) closeIfIdle() {
if VerboseLogs { if VerboseLogs {
cc.vlogf("http2: Transport closing idle conn %p (forSingleUse=%v, maxStream=%v)", cc, cc.singleUse, nextID-2) cc.vlogf("http2: Transport closing idle conn %p (forSingleUse=%v, maxStream=%v)", cc, cc.singleUse, nextID-2)
} }
cc.tconn.Close() cc.closeConn()
} }
func (cc *ClientConn) isDoNotReuseAndIdle() bool { func (cc *ClientConn) isDoNotReuseAndIdle() bool {
@ -938,7 +955,7 @@ func (cc *ClientConn) Shutdown(ctx context.Context) error {
return err return err
} }
// Wait for all in-flight streams to complete or connection to close // Wait for all in-flight streams to complete or connection to close
done := make(chan error, 1) done := make(chan struct{})
cancelled := false // guarded by cc.mu cancelled := false // guarded by cc.mu
go func() { go func() {
cc.mu.Lock() cc.mu.Lock()
@ -946,7 +963,7 @@ func (cc *ClientConn) Shutdown(ctx context.Context) error {
for { for {
if len(cc.streams) == 0 || cc.closed { if len(cc.streams) == 0 || cc.closed {
cc.closed = true cc.closed = true
done <- cc.tconn.Close() close(done)
break break
} }
if cancelled { if cancelled {
@ -957,8 +974,8 @@ func (cc *ClientConn) Shutdown(ctx context.Context) error {
}() }()
shutdownEnterWaitStateHook() shutdownEnterWaitStateHook()
select { select {
case err := <-done: case <-done:
return err return cc.closeConn()
case <-ctx.Done(): case <-ctx.Done():
cc.mu.Lock() cc.mu.Lock()
// Free the goroutine above // Free the goroutine above
@ -1001,9 +1018,9 @@ func (cc *ClientConn) closeForError(err error) error {
for _, cs := range cc.streams { for _, cs := range cc.streams {
cs.abortStreamLocked(err) cs.abortStreamLocked(err)
} }
defer cc.cond.Broadcast() cc.cond.Broadcast()
defer cc.mu.Unlock() cc.mu.Unlock()
return cc.tconn.Close() return cc.closeConn()
} }
// Close closes the client connection immediately. // Close closes the client connection immediately.
@ -1978,7 +1995,7 @@ func (cc *ClientConn) forgetStreamID(id uint32) {
cc.vlogf("http2: Transport closing idle conn %p (forSingleUse=%v, maxStream=%v)", cc, cc.singleUse, cc.nextStreamID-2) cc.vlogf("http2: Transport closing idle conn %p (forSingleUse=%v, maxStream=%v)", cc, cc.singleUse, cc.nextStreamID-2)
} }
cc.closed = true cc.closed = true
defer cc.tconn.Close() defer cc.closeConn()
} }
cc.mu.Unlock() cc.mu.Unlock()
@ -2025,8 +2042,8 @@ func isEOFOrNetReadError(err error) bool {
func (rl *clientConnReadLoop) cleanup() { func (rl *clientConnReadLoop) cleanup() {
cc := rl.cc cc := rl.cc
defer cc.tconn.Close() cc.t.connPool().MarkDead(cc)
defer cc.t.connPool().MarkDead(cc) defer cc.closeConn()
defer close(cc.readerDone) defer close(cc.readerDone)
if cc.idleTimer != nil { if cc.idleTimer != nil {

View File

@ -194,3 +194,26 @@ func ioctlIfreqData(fd int, req uint, value *ifreqData) error {
// identical so pass *IfreqData directly. // identical so pass *IfreqData directly.
return ioctlPtr(fd, req, unsafe.Pointer(value)) return ioctlPtr(fd, req, unsafe.Pointer(value))
} }
// IoctlKCMClone attaches a new file descriptor to a multiplexor by cloning an
// existing KCM socket, returning a structure containing the file descriptor of
// the new socket.
func IoctlKCMClone(fd int) (*KCMClone, error) {
var info KCMClone
if err := ioctlPtr(fd, SIOCKCMCLONE, unsafe.Pointer(&info)); err != nil {
return nil, err
}
return &info, nil
}
// IoctlKCMAttach attaches a TCP socket and associated BPF program file
// descriptor to a multiplexor.
func IoctlKCMAttach(fd int, info KCMAttach) error {
return ioctlPtr(fd, SIOCKCMATTACH, unsafe.Pointer(&info))
}
// IoctlKCMUnattach unattaches a TCP socket file descriptor from a multiplexor.
func IoctlKCMUnattach(fd int, info KCMUnattach) error {
return ioctlPtr(fd, SIOCKCMUNATTACH, unsafe.Pointer(&info))
}

View File

@ -205,6 +205,7 @@ struct ltchars {
#include <linux/bpf.h> #include <linux/bpf.h>
#include <linux/can.h> #include <linux/can.h>
#include <linux/can/error.h> #include <linux/can/error.h>
#include <linux/can/netlink.h>
#include <linux/can/raw.h> #include <linux/can/raw.h>
#include <linux/capability.h> #include <linux/capability.h>
#include <linux/cryptouser.h> #include <linux/cryptouser.h>
@ -231,6 +232,7 @@ struct ltchars {
#include <linux/if_packet.h> #include <linux/if_packet.h>
#include <linux/if_xdp.h> #include <linux/if_xdp.h>
#include <linux/input.h> #include <linux/input.h>
#include <linux/kcm.h>
#include <linux/kexec.h> #include <linux/kexec.h>
#include <linux/keyctl.h> #include <linux/keyctl.h>
#include <linux/landlock.h> #include <linux/landlock.h>
@ -503,6 +505,7 @@ ccflags="$@"
$2 ~ /^O?XTABS$/ || $2 ~ /^O?XTABS$/ ||
$2 ~ /^TC[IO](ON|OFF)$/ || $2 ~ /^TC[IO](ON|OFF)$/ ||
$2 ~ /^IN_/ || $2 ~ /^IN_/ ||
$2 ~ /^KCM/ ||
$2 ~ /^LANDLOCK_/ || $2 ~ /^LANDLOCK_/ ||
$2 ~ /^LOCK_(SH|EX|NB|UN)$/ || $2 ~ /^LOCK_(SH|EX|NB|UN)$/ ||
$2 ~ /^LO_(KEY|NAME)_SIZE$/ || $2 ~ /^LO_(KEY|NAME)_SIZE$/ ||

View File

@ -250,6 +250,13 @@ func Getwd() (wd string, err error) {
if n < 1 || n > len(buf) || buf[n-1] != 0 { if n < 1 || n > len(buf) || buf[n-1] != 0 {
return "", EINVAL return "", EINVAL
} }
// In some cases, Linux can return a path that starts with the
// "(unreachable)" prefix, which can potentially be a valid relative
// path. To work around that, return ENOENT if path is not absolute.
if buf[0] != '/' {
return "", ENOENT
}
return string(buf[0 : n-1]), nil return string(buf[0 : n-1]), nil
} }

View File

@ -173,14 +173,6 @@ const (
_SENDMMSG = 20 _SENDMMSG = 20
) )
func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) {
fd, e := socketcall(_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), 0, 0, 0)
if e != 0 {
err = e
}
return
}
func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) {
fd, e := socketcall(_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) fd, e := socketcall(_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0)
if e != 0 { if e != 0 {

View File

@ -62,7 +62,6 @@ func Stat(path string, stat *Stat_t) (err error) {
//sys SyncFileRange(fd int, off int64, n int64, flags int) (err error) //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
//sys Truncate(path string, length int64) (err error) //sys Truncate(path string, length int64) (err error)
//sys Ustat(dev int, ubuf *Ustat_t) (err error) //sys Ustat(dev int, ubuf *Ustat_t) (err error)
//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
//sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
//sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
//sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)

View File

@ -27,7 +27,6 @@ func Seek(fd int, offset int64, whence int) (newoffset int64, err error) {
return newoffset, nil return newoffset, nil
} }
//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
//sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
//sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
//sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)

View File

@ -66,7 +66,6 @@ func Ustat(dev int, ubuf *Ustat_t) (err error) {
return ENOSYS return ENOSYS
} }
//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
//sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
//sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
//sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)

View File

@ -48,7 +48,6 @@ func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err
//sys SyncFileRange(fd int, off int64, n int64, flags int) (err error) //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
//sys Truncate(path string, length int64) (err error) //sys Truncate(path string, length int64) (err error)
//sys Ustat(dev int, ubuf *Ustat_t) (err error) //sys Ustat(dev int, ubuf *Ustat_t) (err error)
//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
//sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
//sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
//sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)

View File

@ -41,7 +41,6 @@ func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr,
//sys SyncFileRange(fd int, off int64, n int64, flags int) (err error) //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
//sys Truncate(path string, length int64) (err error) = SYS_TRUNCATE64 //sys Truncate(path string, length int64) (err error) = SYS_TRUNCATE64
//sys Ustat(dev int, ubuf *Ustat_t) (err error) //sys Ustat(dev int, ubuf *Ustat_t) (err error)
//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
//sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
//sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
//sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)

View File

@ -43,7 +43,6 @@ import (
//sys Stat(path string, stat *Stat_t) (err error) = SYS_STAT64 //sys Stat(path string, stat *Stat_t) (err error) = SYS_STAT64
//sys Truncate(path string, length int64) (err error) = SYS_TRUNCATE64 //sys Truncate(path string, length int64) (err error) = SYS_TRUNCATE64
//sys Ustat(dev int, ubuf *Ustat_t) (err error) //sys Ustat(dev int, ubuf *Ustat_t) (err error)
//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
//sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
//sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
//sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)

View File

@ -45,7 +45,6 @@ package unix
//sys Statfs(path string, buf *Statfs_t) (err error) //sys Statfs(path string, buf *Statfs_t) (err error)
//sys Truncate(path string, length int64) (err error) //sys Truncate(path string, length int64) (err error)
//sys Ustat(dev int, ubuf *Ustat_t) (err error) //sys Ustat(dev int, ubuf *Ustat_t) (err error)
//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
//sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
//sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
//sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)

View File

@ -65,7 +65,6 @@ func Ustat(dev int, ubuf *Ustat_t) (err error) {
return ENOSYS return ENOSYS
} }
//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
//sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
//sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
//sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)

View File

@ -145,15 +145,6 @@ const (
netSendMMsg = 20 netSendMMsg = 20
) )
func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (int, error) {
args := [3]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))}
fd, _, err := Syscall(SYS_SOCKETCALL, netAccept, uintptr(unsafe.Pointer(&args)), 0)
if err != 0 {
return 0, err
}
return int(fd), nil
}
func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (int, error) { func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (int, error) {
args := [4]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags)} args := [4]uintptr{uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags)}
fd, _, err := Syscall(SYS_SOCKETCALL, netAccept4, uintptr(unsafe.Pointer(&args)), 0) fd, _, err := Syscall(SYS_SOCKETCALL, netAccept4, uintptr(unsafe.Pointer(&args)), 0)

View File

@ -42,7 +42,6 @@ package unix
//sys Statfs(path string, buf *Statfs_t) (err error) //sys Statfs(path string, buf *Statfs_t) (err error)
//sys SyncFileRange(fd int, off int64, n int64, flags int) (err error) //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
//sys Truncate(path string, length int64) (err error) //sys Truncate(path string, length int64) (err error)
//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
//sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
//sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
//sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)

View File

@ -260,6 +260,17 @@ const (
BUS_USB = 0x3 BUS_USB = 0x3
BUS_VIRTUAL = 0x6 BUS_VIRTUAL = 0x6
CAN_BCM = 0x2 CAN_BCM = 0x2
CAN_CTRLMODE_3_SAMPLES = 0x4
CAN_CTRLMODE_BERR_REPORTING = 0x10
CAN_CTRLMODE_CC_LEN8_DLC = 0x100
CAN_CTRLMODE_FD = 0x20
CAN_CTRLMODE_FD_NON_ISO = 0x80
CAN_CTRLMODE_LISTENONLY = 0x2
CAN_CTRLMODE_LOOPBACK = 0x1
CAN_CTRLMODE_ONE_SHOT = 0x8
CAN_CTRLMODE_PRESUME_ACK = 0x40
CAN_CTRLMODE_TDC_AUTO = 0x200
CAN_CTRLMODE_TDC_MANUAL = 0x400
CAN_EFF_FLAG = 0x80000000 CAN_EFF_FLAG = 0x80000000
CAN_EFF_ID_BITS = 0x1d CAN_EFF_ID_BITS = 0x1d
CAN_EFF_MASK = 0x1fffffff CAN_EFF_MASK = 0x1fffffff
@ -337,6 +348,7 @@ const (
CAN_RTR_FLAG = 0x40000000 CAN_RTR_FLAG = 0x40000000
CAN_SFF_ID_BITS = 0xb CAN_SFF_ID_BITS = 0xb
CAN_SFF_MASK = 0x7ff CAN_SFF_MASK = 0x7ff
CAN_TERMINATION_DISABLED = 0x0
CAN_TP16 = 0x3 CAN_TP16 = 0x3
CAN_TP20 = 0x4 CAN_TP20 = 0x4
CAP_AUDIT_CONTROL = 0x1e CAP_AUDIT_CONTROL = 0x1e
@ -1274,6 +1286,8 @@ const (
IUTF8 = 0x4000 IUTF8 = 0x4000
IXANY = 0x800 IXANY = 0x800
JFFS2_SUPER_MAGIC = 0x72b6 JFFS2_SUPER_MAGIC = 0x72b6
KCMPROTO_CONNECTED = 0x0
KCM_RECV_DISABLE = 0x1
KEXEC_ARCH_386 = 0x30000 KEXEC_ARCH_386 = 0x30000
KEXEC_ARCH_68K = 0x40000 KEXEC_ARCH_68K = 0x40000
KEXEC_ARCH_AARCH64 = 0xb70000 KEXEC_ARCH_AARCH64 = 0xb70000
@ -2446,6 +2460,9 @@ const (
SIOCGSTAMPNS = 0x8907 SIOCGSTAMPNS = 0x8907
SIOCGSTAMPNS_OLD = 0x8907 SIOCGSTAMPNS_OLD = 0x8907
SIOCGSTAMP_OLD = 0x8906 SIOCGSTAMP_OLD = 0x8906
SIOCKCMATTACH = 0x89e0
SIOCKCMCLONE = 0x89e2
SIOCKCMUNATTACH = 0x89e1
SIOCOUTQNSD = 0x894b SIOCOUTQNSD = 0x894b
SIOCPROTOPRIVATE = 0x89e0 SIOCPROTOPRIVATE = 0x89e0
SIOCRTMSG = 0x890d SIOCRTMSG = 0x890d

View File

@ -444,17 +444,6 @@ func Ustat(dev int, ubuf *Ustat_t) (err error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) {
r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
fd = int(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) {
r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0)
fd = int(r0) fd = int(r0)

View File

@ -46,17 +46,6 @@ func Tee(rfd int, wfd int, len int, flags int) (n int64, err error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) {
r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
fd = int(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) {
r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0)
fd = int(r0) fd = int(r0)

View File

@ -389,17 +389,6 @@ func Truncate(path string, length int64) (err error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) {
r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
fd = int(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) {
r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0)
fd = int(r0) fd = int(r0)

View File

@ -344,17 +344,6 @@ func Ustat(dev int, ubuf *Ustat_t) (err error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) {
r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
fd = int(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) {
r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0)
fd = int(r0) fd = int(r0)

View File

@ -399,17 +399,6 @@ func Ustat(dev int, ubuf *Ustat_t) (err error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) {
r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
fd = int(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) {
r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0)
fd = int(r0) fd = int(r0)

View File

@ -399,17 +399,6 @@ func Ustat(dev int, ubuf *Ustat_t) (err error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) {
r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
fd = int(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) {
r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0)
fd = int(r0) fd = int(r0)

View File

@ -344,17 +344,6 @@ func Ustat(dev int, ubuf *Ustat_t) (err error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) {
r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
fd = int(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) {
r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0)
fd = int(r0) fd = int(r0)

View File

@ -409,17 +409,6 @@ func Ustat(dev int, ubuf *Ustat_t) (err error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) {
r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
fd = int(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) {
r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0)
fd = int(r0) fd = int(r0)

View File

@ -475,17 +475,6 @@ func Ustat(dev int, ubuf *Ustat_t) (err error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) {
r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
fd = int(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) {
r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0)
fd = int(r0) fd = int(r0)

View File

@ -475,17 +475,6 @@ func Ustat(dev int, ubuf *Ustat_t) (err error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) {
r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
fd = int(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) {
r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0)
fd = int(r0) fd = int(r0)

View File

@ -369,17 +369,6 @@ func Truncate(path string, length int64) (err error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) {
r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
fd = int(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) {
r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0)
fd = int(r0) fd = int(r0)

View File

@ -455,17 +455,6 @@ func Truncate(path string, length int64) (err error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) {
r0, _, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
fd = int(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) { func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) {
r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0) r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0)
fd = int(r0) fd = int(r0)

File diff suppressed because it is too large Load Diff

View File

@ -210,8 +210,8 @@ type PtraceFpregs struct {
} }
type PtracePer struct { type PtracePer struct {
_ [0]uint64 Control_regs [3]uint64
_ [32]byte _ [8]byte
Starting_addr uint64 Starting_addr uint64
Ending_addr uint64 Ending_addr uint64
Perc_atmid uint16 Perc_atmid uint16

23
vendor/gopkg.in/zeromq/goczmq.v4/.gitignore generated vendored Normal file
View File

@ -0,0 +1,23 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test

17
vendor/gopkg.in/zeromq/goczmq.v4/.travis.yml generated vendored Normal file
View File

@ -0,0 +1,17 @@
language: go
warnings_are_errors: false
addons:
apt:
sources:
- sourceline: 'deb http://download.opensuse.org/repositories/network:/messaging:/zeromq:/git-draft/xUbuntu_12.04/ ./'
key_url: 'http://download.opensuse.org/repositories/network:/messaging:/zeromq:/git-draft/xUbuntu_12.04/Release.key'
packages:
- libsodium-dev
- libczmq-dev
go:
- 1.7.1
script:
- go get -t -v ./...
- go test -v .

15
vendor/gopkg.in/zeromq/goczmq.v4/AUTHORS generated vendored Normal file
View File

@ -0,0 +1,15 @@
Contributors (no particular order)
==================================
Brian Knox
Luna Duclos
Indradhanush Gupta
Armen Baghumian
Ben Aldrich
Jordan Sissel
Nick Bargnesi
Cyrille Verrier
Ben Aldrich
Matthew Campbell
James Reuss
Pieter Hintjens

22
vendor/gopkg.in/zeromq/goczmq.v4/CONTRIBUTING.md generated vendored Normal file
View File

@ -0,0 +1,22 @@
# Contributing to GoCZMQ
The contributors are listed in AUTHORS (add yourself). This project uses the MPL v2 license, see LICENSE.
# Our Process
Before you send a pull request, please familiarize yourself with the [C4.1 Collective Code Construction Contract](http://rfc.zeromq.org/spec:22) process. A quick summary (but please, do read the process document):
* A Pull Request should be described in the form of a problem statement.
* The code included with the pull request should be a proposed solution to that problem.
* The submitted code should adhere to our style guidelines (described below).
* The submitted code should include tests.
* The submitted code should not break any existing tests.
"A Problem" should be one single clear problem. Large complex problems should be broken down into a series of smaller problems when ever possible.
**Please be aware** that GoCZMQ is **not versioned**. We merge to master. We deploy from master. Master is epxected to be working, at all times. We strive to do our very best to never break public API in this library. Changes can be additive, but they can not break the existing API. If a case arises where we need to, we will be loud about it on the ZeroMQ mailing list and try to build consensus among current maintainers that it's necessary. We will be very chagrined about it, and you can poke fun at us a bit.
# Style Guide
* Your code must be formatted with [Gofmt](https://blog.golang.org/go-fmt-your-code)
* Your code should pass [golint](https://github.com/golang/lint). If for some reason it cannot, please provide an explanation.
* Your code should pass [go vet](https://golang.org/cmd/vet/)

362
vendor/gopkg.in/zeromq/goczmq.v4/LICENSE generated vendored Normal file
View File

@ -0,0 +1,362 @@
Mozilla Public License, version 2.0
1. Definitions
1.1. "Contributor"
means each individual or legal entity that creates, contributes to the
creation of, or owns Covered Software.
1.2. "Contributor Version"
means the combination of the Contributions of others (if any) used by a
Contributor and that particular Contributor's Contribution.
1.3. "Contribution"
means Covered Software of a particular Contributor.
1.4. "Covered Software"
means Source Code Form to which the initial Contributor has attached the
notice in Exhibit A, the Executable Form of such Source Code Form, and
Modifications of such Source Code Form, in each case including portions
thereof.
1.5. "Incompatible With Secondary Licenses"
means
a. that the initial Contributor has attached the notice described in
Exhibit B to the Covered Software; or
b. that the Covered Software was made available under the terms of
version 1.1 or earlier of the License, but not also under the terms of
a Secondary License.
1.6. "Executable Form"
means any form of the work other than Source Code Form.
1.7. "Larger Work"
means a work that combines Covered Software with other material, in a
separate file or files, that is not Covered Software.
1.8. "License"
means this document.
1.9. "Licensable"
means having the right to grant, to the maximum extent possible, whether
at the time of the initial grant or subsequently, any and all of the
rights conveyed by this License.
1.10. "Modifications"
means any of the following:
a. any file in Source Code Form that results from an addition to,
deletion from, or modification of the contents of Covered Software; or
b. any new file in Source Code Form that contains any Covered Software.
1.11. "Patent Claims" of a Contributor
means any patent claim(s), including without limitation, method,
process, and apparatus claims, in any patent Licensable by such
Contributor that would be infringed, but for the grant of the License,
by the making, using, selling, offering for sale, having made, import,
or transfer of either its Contributions or its Contributor Version.
1.12. "Secondary License"
means either the GNU General Public License, Version 2.0, the GNU Lesser
General Public License, Version 2.1, the GNU Affero General Public
License, Version 3.0, or any later versions of those licenses.
1.13. "Source Code Form"
means the form of the work preferred for making modifications.
1.14. "You" (or "Your")
means an individual or a legal entity exercising rights under this
License. For legal entities, "You" includes any entity that controls, is
controlled by, or is under common control with You. For purposes of this
definition, "control" means (a) the power, direct or indirect, to cause
the direction or management of such entity, whether by contract or
otherwise, or (b) ownership of more than fifty percent (50%) of the
outstanding shares or beneficial ownership of such entity.
2. License Grants and Conditions
2.1. Grants
Each Contributor hereby grants You a world-wide, royalty-free,
non-exclusive license:
a. under intellectual property rights (other than patent or trademark)
Licensable by such Contributor to use, reproduce, make available,
modify, display, perform, distribute, and otherwise exploit its
Contributions, either on an unmodified basis, with Modifications, or
as part of a Larger Work; and
b. under Patent Claims of such Contributor to make, use, sell, offer for
sale, have made, import, and otherwise transfer either its
Contributions or its Contributor Version.
2.2. Effective Date
The licenses granted in Section 2.1 with respect to any Contribution
become effective for each Contribution on the date the Contributor first
distributes such Contribution.
2.3. Limitations on Grant Scope
The licenses granted in this Section 2 are the only rights granted under
this License. No additional rights or licenses will be implied from the
distribution or licensing of Covered Software under this License.
Notwithstanding Section 2.1(b) above, no patent license is granted by a
Contributor:
a. for any code that a Contributor has removed from Covered Software; or
b. for infringements caused by: (i) Your and any other third party's
modifications of Covered Software, or (ii) the combination of its
Contributions with other software (except as part of its Contributor
Version); or
c. under Patent Claims infringed by Covered Software in the absence of
its Contributions.
This License does not grant any rights in the trademarks, service marks,
or logos of any Contributor (except as may be necessary to comply with
the notice requirements in Section 3.4).
2.4. Subsequent Licenses
No Contributor makes additional grants as a result of Your choice to
distribute the Covered Software under a subsequent version of this
License (see Section 10.2) or under the terms of a Secondary License (if
permitted under the terms of Section 3.3).
2.5. Representation
Each Contributor represents that the Contributor believes its
Contributions are its original creation(s) or it has sufficient rights to
grant the rights to its Contributions conveyed by this License.
2.6. Fair Use
This License is not intended to limit any rights You have under
applicable copyright doctrines of fair use, fair dealing, or other
equivalents.
2.7. Conditions
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
Section 2.1.
3. Responsibilities
3.1. Distribution of Source Form
All distribution of Covered Software in Source Code Form, including any
Modifications that You create or to which You contribute, must be under
the terms of this License. You must inform recipients that the Source
Code Form of the Covered Software is governed by the terms of this
License, and how they can obtain a copy of this License. You may not
attempt to alter or restrict the recipients' rights in the Source Code
Form.
3.2. Distribution of Executable Form
If You distribute Covered Software in Executable Form then:
a. such Covered Software must also be made available in Source Code Form,
as described in Section 3.1, and You must inform recipients of the
Executable Form how they can obtain a copy of such Source Code Form by
reasonable means in a timely manner, at a charge no more than the cost
of distribution to the recipient; and
b. You may distribute such Executable Form under the terms of this
License, or sublicense it under different terms, provided that the
license for the Executable Form does not attempt to limit or alter the
recipients' rights in the Source Code Form under this License.
3.3. Distribution of a Larger Work
You may create and distribute a Larger Work under terms of Your choice,
provided that You also comply with the requirements of this License for
the Covered Software. If the Larger Work is a combination of Covered
Software with a work governed by one or more Secondary Licenses, and the
Covered Software is not Incompatible With Secondary Licenses, this
License permits You to additionally distribute such Covered Software
under the terms of such Secondary License(s), so that the recipient of
the Larger Work may, at their option, further distribute the Covered
Software under the terms of either this License or such Secondary
License(s).
3.4. Notices
You may not remove or alter the substance of any license notices
(including copyright notices, patent notices, disclaimers of warranty, or
limitations of liability) contained within the Source Code Form of the
Covered Software, except that You may alter any license notices to the
extent required to remedy known factual inaccuracies.
3.5. Application of Additional Terms
You may choose to offer, and to charge a fee for, warranty, support,
indemnity or liability obligations to one or more recipients of Covered
Software. However, You may do so only on Your own behalf, and not on
behalf of any Contributor. You must make it absolutely clear that any
such warranty, support, indemnity, or liability obligation is offered by
You alone, and You hereby agree to indemnify every Contributor for any
liability incurred by such Contributor as a result of warranty, support,
indemnity or liability terms You offer. You may include additional
disclaimers of warranty and limitations of liability specific to any
jurisdiction.
4. Inability to Comply Due to Statute or Regulation
If it is impossible for You to comply with any of the terms of this License
with respect to some or all of the Covered Software due to statute,
judicial order, or regulation then You must: (a) comply with the terms of
this License to the maximum extent possible; and (b) describe the
limitations and the code they affect. Such description must be placed in a
text file included with all distributions of the Covered Software under
this License. Except to the extent prohibited by statute or regulation,
such description must be sufficiently detailed for a recipient of ordinary
skill to be able to understand it.
5. Termination
5.1. The rights granted under this License will terminate automatically if You
fail to comply with any of its terms. However, if You become compliant,
then the rights granted under this License from a particular Contributor
are reinstated (a) provisionally, unless and until such Contributor
explicitly and finally terminates Your grants, and (b) on an ongoing
basis, if such Contributor fails to notify You of the non-compliance by
some reasonable means prior to 60 days after You have come back into
compliance. Moreover, Your grants from a particular Contributor are
reinstated on an ongoing basis if such Contributor notifies You of the
non-compliance by some reasonable means, this is the first time You have
received notice of non-compliance with this License from such
Contributor, and You become compliant prior to 30 days after Your receipt
of the notice.
5.2. If You initiate litigation against any entity by asserting a patent
infringement claim (excluding declaratory judgment actions,
counter-claims, and cross-claims) alleging that a Contributor Version
directly or indirectly infringes any patent, then the rights granted to
You by any and all Contributors for the Covered Software under Section
2.1 of this License shall terminate.
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
license agreements (excluding distributors and resellers) which have been
validly granted by You or Your distributors under this License prior to
termination shall survive termination.
6. Disclaimer of Warranty
Covered Software is provided under this License on an "as is" basis,
without warranty of any kind, either expressed, implied, or statutory,
including, without limitation, warranties that the Covered Software is free
of defects, merchantable, fit for a particular purpose or non-infringing.
The entire risk as to the quality and performance of the Covered Software
is with You. Should any Covered Software prove defective in any respect,
You (not any Contributor) assume the cost of any necessary servicing,
repair, or correction. This disclaimer of warranty constitutes an essential
part of this License. No use of any Covered Software is authorized under
this License except under this disclaimer.
7. Limitation of Liability
Under no circumstances and under no legal theory, whether tort (including
negligence), contract, or otherwise, shall any Contributor, or anyone who
distributes Covered Software as permitted above, be liable to You for any
direct, indirect, special, incidental, or consequential damages of any
character including, without limitation, damages for lost profits, loss of
goodwill, work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses, even if such party shall have been
informed of the possibility of such damages. This limitation of liability
shall not apply to liability for death or personal injury resulting from
such party's negligence to the extent applicable law prohibits such
limitation. Some jurisdictions do not allow the exclusion or limitation of
incidental or consequential damages, so this exclusion and limitation may
not apply to You.
8. Litigation
Any litigation relating to this License may be brought only in the courts
of a jurisdiction where the defendant maintains its principal place of
business and such litigation shall be governed by laws of that
jurisdiction, without reference to its conflict-of-law provisions. Nothing
in this Section shall prevent a party's ability to bring cross-claims or
counter-claims.
9. Miscellaneous
This License represents the complete agreement concerning the subject
matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent
necessary to make it enforceable. Any law or regulation which provides that
the language of a contract shall be construed against the drafter shall not
be used to construe this License against a Contributor.
10. Versions of the License
10.1. New Versions
Mozilla Foundation is the license steward. Except as provided in Section
10.3, no one other than the license steward has the right to modify or
publish new versions of this License. Each version will be given a
distinguishing version number.
10.2. Effect of New Versions
You may distribute the Covered Software under the terms of the version
of the License under which You originally received the Covered Software,
or under the terms of any subsequent version published by the license
steward.
10.3. Modified Versions
If you create software not governed by this License, and you want to
create a new license for such software, you may create and use a
modified version of this License if you rename the license and remove
any references to the name of the license steward (except to note that
such modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary
Licenses If You choose to distribute Source Code Form that is
Incompatible With Secondary Licenses under the terms of this version of
the License, the notice described in Exhibit B of this License must be
attached.
Exhibit A - Source Code Form License Notice
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular file,
then You may include the notice in a location (such as a LICENSE file in a
relevant directory) where a recipient would be likely to look for such a
notice.
You may add additional accurate notices of copyright ownership.
Exhibit B - "Incompatible With Secondary Licenses" Notice
This Source Code Form is "Incompatible
With Secondary Licenses", as defined by
the Mozilla Public License, v. 2.0.

18
vendor/gopkg.in/zeromq/goczmq.v4/Makefile generated vendored Normal file
View File

@ -0,0 +1,18 @@
build: format clean test
go build ./...
test: get
go test -v .
bench: get
go test -v -bench . ./...
get:
go get -t -v ./...
format:
find . -name \*.go -type f -exec gofmt -w {} \;
clean:
.PHONY: clean build

261
vendor/gopkg.in/zeromq/goczmq.v4/README.md generated vendored Normal file
View File

@ -0,0 +1,261 @@
# goczmq [![Build Status](https://travis-ci.org/zeromq/goczmq.svg?branch=master)](https://travis-ci.org/zeromq/goczmq) [![Doc Status](https://godoc.org/github.com/zeromq/goczmq?status.png)](https://godoc.org/github.com/zeromq/goczmq)
## Introduction
A golang interface to the [CZMQ v4.2](http://czmq.zeromq.org) API.
## Install
### Dependencies
* [libsodium](https://github.com/jedisct1/libsodium)
* [libzmq](https://github.com/zeromq/libzmq)
* [czmq](https://github.com/zeromq/czmq)
### For CZMQ master
```
go get github.com/zeromq/goczmq
```
#### A Note on Build Tags
The CZMQ library includes experimental classes that are not built by default, but can be built
by passing `--enable-drafts` to configure. Support for these draft classes are being added
to goczmq. To build these features against a CZMQ that has been compiled with `--enable-drafts`,
use `go build -tags draft`.
### For CMZQ = 4.0
```
go get gopkg.in/zeromq/goczmq.v4
```
### For CZMQ Before 4.0
```
go get gopkg.in/zeromq/goczmq.v1
```
## Usage
### Direct CZMQ Sock API
#### Example
```go
package main
import (
"log"
"github.com/zeromq/goczmq"
)
func main() {
// Create a router socket and bind it to port 5555.
router, err := goczmq.NewRouter("tcp://*:5555")
if err != nil {
log.Fatal(err)
}
defer router.Destroy()
log.Println("router created and bound")
// Create a dealer socket and connect it to the router.
dealer, err := goczmq.NewDealer("tcp://127.0.0.1:5555")
if err != nil {
log.Fatal(err)
}
defer dealer.Destroy()
log.Println("dealer created and connected")
// Send a 'Hello' message from the dealer to the router.
// Here we send it as a frame ([]byte), with a FlagNone
// flag to indicate there are no more frames following.
err = dealer.SendFrame([]byte("Hello"), goczmq.FlagNone)
if err != nil {
log.Fatal(err)
}
log.Println("dealer sent 'Hello'")
// Receve the message. Here we call RecvMessage, which
// will return the message as a slice of frames ([][]byte).
// Since this is a router socket that support async
// request / reply, the first frame of the message will
// be the routing frame.
request, err := router.RecvMessage()
if err != nil {
log.Fatal(err)
}
log.Printf("router received '%s' from '%v'", request[1], request[0])
// Send a reply. First we send the routing frame, which
// lets the dealer know which client to send the message.
// The FlagMore flag tells the router there will be more
// frames in this message.
err = router.SendFrame(request[0], goczmq.FlagMore)
if err != nil {
log.Fatal(err)
}
log.Printf("router sent 'World'")
// Next send the reply. The FlagNone flag tells the router
// that this is the last frame of the message.
err = router.SendFrame([]byte("World"), goczmq.FlagNone)
if err != nil {
log.Fatal(err)
}
// Receive the reply.
reply, err := dealer.RecvMessage()
if err != nil {
log.Fatal(err)
}
log.Printf("dealer received '%s'", string(reply[0]))
}
```
#### Output
```
2015/05/26 21:52:52 router created and bound
2015/05/26 21:52:52 dealer created and connected
2015/05/26 21:52:52 dealer sent 'Hello'
2015/05/26 21:52:52 router received 'Hello' from '[0 103 84 189 175]'
2015/05/26 21:52:52 router sent 'World'
2015/05/26 21:52:52 dealer received 'World'
```
### io.ReadWriter support
#### Example
```go
package main
import (
"log"
"github.com/zeromq/goczmq"
)
func main() {
// Create a router socket and bind it to port 5555.
router, err := goczmq.NewRouter("tcp://*:5555")
if err != nil {
log.Fatal(err)
}
defer router.Destroy()
log.Println("router created and bound")
// Create a dealer socket and connect it to the router.
dealer, err := goczmq.NewDealer("tcp://127.0.0.1:5555")
if err != nil {
log.Fatal(err)
}
defer dealer.Destroy()
log.Println("dealer created and connected")
// Send a 'Hello' message from the dealer to the router,
// using the io.Write interface
n, err := dealer.Write([]byte("Hello"))
if err != nil {
log.Fatal(err)
}
log.Printf("dealer sent %d byte message 'Hello'\n", n)
// Make a byte slice and pass it to the router
// Read interface. When using the ReadWriter
// interface with a router socket, the router
// caches the routing frames internally in a
// FIFO and uses them transparently when
// sending replies.
buf := make([]byte, 16386)
n, err = router.Read(buf)
if err != nil {
log.Fatal(err)
}
log.Printf("router received '%s'\n", buf[:n])
// Send a reply.
n, err = router.Write([]byte("World"))
if err != nil {
log.Fatal(err)
}
log.Printf("router sent %d byte message 'World'\n", n)
// Receive the reply, reusing the previous buffer.
n, err = dealer.Read(buf)
if err != nil {
log.Fatal(err)
}
log.Printf("dealer received '%s'", string(buf[:n]))
}
```
#### Output
```
2015/05/26 21:54:10 router created and bound
2015/05/26 21:54:10 dealer created and connected
2015/05/26 21:54:10 dealer sent 5 byte message 'Hello'
2015/05/26 21:54:10 router received 'Hello'
2015/05/26 21:54:10 router sent 5 byte message 'World'
2015/05/26 21:54:10 dealer received 'World'
```
### Thread safe channel interface
#### Example
```go
package main
import (
"log"
"github.com/zeromq/goczmq"
)
func main() {
// Create a router channeler and bind it to port 5555.
// A channeler provides a thread safe channel interface
// to a *Sock
router := goczmq.NewRouterChanneler("tcp://*:5555")
defer router.Destroy()
log.Println("router created and bound")
// Create a dealer channeler and connect it to the router.
dealer := goczmq.NewDealerChanneler("tcp://127.0.0.1:5555")
defer dealer.Destroy()
log.Println("dealer created and connected")
// Send a 'Hello' message from the dealer to the router.
dealer.SendChan <- [][]byte{[]byte("Hello")}
log.Println("dealer sent 'Hello'")
// Receve the message as a [][]byte. Since this is
// a router, the first frame of the message wil
// be the routing frame.
request := <-router.RecvChan
log.Printf("router received '%s' from '%v'", request[1], request[0])
// Send a reply. First we send the routing frame, which
// lets the dealer know which client to send the message.
router.SendChan <- [][]byte{request[0], []byte("World")}
log.Printf("router sent 'World'")
// Receive the reply.
reply := <-dealer.RecvChan
log.Printf("dealer received '%s'", string(reply[0]))
}
```
#### Output
```
2015/05/26 21:56:43 router created and bound
2015/05/26 21:56:43 dealer created and connected
2015/05/26 21:56:43 dealer sent 'Hello'
2015/05/26 21:56:43 received 'Hello' from '[0 12 109 153 35]'
2015/05/26 21:56:43 router sent 'World'
2015/05/26 21:56:43 dealer received 'World'
```
## GoDoc
[godoc](https://godoc.org/github.com/zeromq/goczmq)
## See Also
* [Peter Kleiweg's](https://github.com/pebbe) [zmq4](https://github.com/pebbe/zmq4) bindings
## License
This project uses the MPL v2 license, see LICENSE

140
vendor/gopkg.in/zeromq/goczmq.v4/auth.go generated vendored Normal file
View File

@ -0,0 +1,140 @@
package goczmq
/*
#include "czmq.h"
zactor_t *Auth_new () {
zactor_t *auth = zactor_new(zauth, NULL); return auth;
}
*/
import "C"
import (
"unsafe"
)
// Auth wraps the CZMQ zauth actor. It handles authentication
// for all incoming connections. It allows whitelisting and
// blackisting peers based on IP address and support
// PLAIN and CURVE authentication policies.
type Auth struct {
zactorT *C.struct__zactor_t
}
// NewAuth creates a new Auth actor.
func NewAuth() *Auth {
z := &Auth{}
z.zactorT = C.Auth_new()
return z
}
// Verbose sets the auth actor to log information to stdout.
func (a *Auth) Verbose() error {
cmd := C.CString("VERBOSE")
defer C.free(unsafe.Pointer(cmd))
rc := C.zstr_send(unsafe.Pointer(a.zactorT), cmd)
if rc == -1 {
return ErrActorCmd
}
C.zsock_wait(unsafe.Pointer(a.zactorT))
return nil
}
// Deny adds an address to a socket's deny list
func (a *Auth) Deny(address string) error {
cmd := C.CString("DENY")
defer C.free(unsafe.Pointer(cmd))
cAddress := C.CString(address)
defer C.free(unsafe.Pointer(cAddress))
rc := C.zstr_sendm(unsafe.Pointer(a.zactorT), cmd)
if rc == -1 {
return ErrActorCmd
}
rc = C.zstr_send(unsafe.Pointer(a.zactorT), cAddress)
if rc == -1 {
return ErrActorCmd
}
C.zsock_wait(unsafe.Pointer(a.zactorT))
return nil
}
// Allow removes a previous Deny
func (a *Auth) Allow(address string) error {
cmd := C.CString("ALLOW")
defer C.free(unsafe.Pointer(cmd))
cAddress := C.CString(address)
defer C.free(unsafe.Pointer(cAddress))
rc := C.zstr_sendm(unsafe.Pointer(a.zactorT), cmd)
if rc == -1 {
return ErrActorCmd
}
rc = C.zstr_send(unsafe.Pointer(a.zactorT), cAddress)
if rc == -1 {
return ErrActorCmd
}
C.zsock_wait(unsafe.Pointer(a.zactorT))
return nil
}
// Curve sets auth method to curve
func (a *Auth) Curve(allowed string) error {
cmd := C.CString("CURVE")
defer C.free(unsafe.Pointer(cmd))
cAllowed := C.CString(allowed)
defer C.free(unsafe.Pointer(cAllowed))
rc := C.zstr_sendm(unsafe.Pointer(a.zactorT), cmd)
if rc == -1 {
return ErrActorCmd
}
rc = C.zstr_send(unsafe.Pointer(a.zactorT), cAllowed)
if rc == -1 {
return ErrActorCmd
}
C.zsock_wait(unsafe.Pointer(a.zactorT))
return nil
}
// Plain sets auth method to plain
func (a *Auth) Plain(directory string) error {
cmd := C.CString("PLAIN")
defer C.free(unsafe.Pointer(cmd))
cDirectory := C.CString(directory)
defer C.free(unsafe.Pointer(cDirectory))
rc := C.zstr_sendm(unsafe.Pointer(a.zactorT), cmd)
if rc == -1 {
return ErrActorCmd
}
rc = C.zstr_send(unsafe.Pointer(a.zactorT), cDirectory)
if rc == -1 {
return ErrActorCmd
}
C.zsock_wait(unsafe.Pointer(a.zactorT))
return nil
}
// Destroy destroys the auth actor.
func (a *Auth) Destroy() {
C.zactor_destroy(&a.zactorT)
}

162
vendor/gopkg.in/zeromq/goczmq.v4/beacon.go generated vendored Normal file
View File

@ -0,0 +1,162 @@
package goczmq
/*
#include "czmq.h"
zactor_t *Beacon_new () {
zactor_t *beacon = zactor_new(zbeacon, NULL); return beacon;
}
int Beacon_publish(void *actor, void *data, int size, int interval) {
return zsock_send(actor, "sbi", "PUBLISH", (byte*)data, size, interval);
}
*/
import "C"
import (
"strconv"
"unsafe"
)
// Beacon wraps the CZMQ beacon actor. It implements a
// peer-to-peer discovery service for local networks. Beacons
// can broadcast and receive UDPv4 service broadcasts.
type Beacon struct {
zactorT *C.struct__zactor_t
}
// NewBeacon creates a new Beacon instance.
func NewBeacon() *Beacon {
z := &Beacon{}
z.zactorT = C.Beacon_new()
return z
}
// Verbose sets the beacon to log information to stdout.
func (b *Beacon) Verbose() error {
cmd := C.CString("VERBOSE")
defer C.free(unsafe.Pointer(cmd))
rc := C.zstr_send(unsafe.Pointer(b.zactorT), cmd)
if rc == -1 {
return ErrActorCmd
}
return nil
}
// Configure accepts a port number and configures
// the beacon, returning an address
func (b *Beacon) Configure(port int) (string, error) {
cmd := C.CString("CONFIGURE")
defer C.free(unsafe.Pointer(cmd))
cPort := C.CString(strconv.Itoa(port))
defer C.free(unsafe.Pointer(cPort))
rc := C.zstr_sendm(unsafe.Pointer(b.zactorT), cmd)
if rc == -1 {
return "", ErrActorCmd
}
rc = C.zstr_send(unsafe.Pointer(b.zactorT), cPort)
if rc == -1 {
return "", ErrActorCmd
}
cHostname := C.zstr_recv(unsafe.Pointer(b.zactorT))
hostname := C.GoString(cHostname)
return hostname, nil
}
// Publish publishes an announcement string at an interval
func (b *Beacon) Publish(announcement string, interval int) error {
cmd := C.CString("PUBLISH")
defer C.free(unsafe.Pointer(cmd))
cAnnouncement := C.CString(announcement)
defer C.free(unsafe.Pointer(cAnnouncement))
cInterval := C.CString(strconv.Itoa(interval))
defer C.free(unsafe.Pointer(cInterval))
rc := C.zstr_sendm(unsafe.Pointer(b.zactorT), cmd)
if rc == -1 {
return ErrActorCmd
}
rc = C.zstr_sendm(unsafe.Pointer(b.zactorT), cAnnouncement)
if rc == -1 {
return ErrActorCmd
}
rc = C.zstr_send(unsafe.Pointer(b.zactorT), cInterval)
if rc == -1 {
return ErrActorCmd
}
return nil
}
// PublishBytes publishes an announcement byte slice at an interval
func (b *Beacon) PublishBytes(announcement []byte, interval int) error {
rc := C.Beacon_publish(
unsafe.Pointer(b.zactorT),
unsafe.Pointer(&announcement[0]),
C.int(len(announcement)),
C.int(interval),
)
if rc == -1 {
return ErrActorCmd
}
return nil
}
// Subscribe subscribes to beacons matching the filter
func (b *Beacon) Subscribe(filter string) error {
cmd := C.CString("SUBSCRIBE")
defer C.free(unsafe.Pointer(cmd))
cFilter := C.CString(filter)
defer C.free(unsafe.Pointer(cFilter))
rc := C.zstr_sendm(unsafe.Pointer(b.zactorT), cmd)
if rc == -1 {
return ErrActorCmd
}
rc = C.zstr_send(unsafe.Pointer(b.zactorT), cFilter)
if rc == -1 {
return ErrActorCmd
}
return nil
}
// Recv waits for the specific timeout in milliseconds to receive a beacon
func (b *Beacon) Recv(timeout int) [][]byte {
C.zsock_set_rcvtimeo(unsafe.Pointer(b.zactorT), C.int(timeout))
cAddrFrame := C.zframe_recv(unsafe.Pointer(b.zactorT))
defer C.zframe_destroy(&cAddrFrame)
if cAddrFrame == nil {
return nil
}
addr := C.GoBytes(unsafe.Pointer(C.zframe_data(cAddrFrame)), C.int(C.zframe_size(cAddrFrame)))
cBeaconFrame := C.zframe_recv(unsafe.Pointer(b.zactorT))
defer C.zframe_destroy(&cBeaconFrame)
if cBeaconFrame == nil {
return nil
}
beacon := C.GoBytes(unsafe.Pointer(C.zframe_data(cBeaconFrame)), C.int(C.zframe_size(cBeaconFrame)))
return [][]byte{addr, beacon}
}
// Destroy destroys the beacon.
func (b *Beacon) Destroy() {
C.zactor_destroy(&b.zactorT)
}

158
vendor/gopkg.in/zeromq/goczmq.v4/cert.go generated vendored Normal file
View File

@ -0,0 +1,158 @@
package goczmq
/*
#include "czmq.h"
void Set_meta(zcert_t *self, const char *key, const char *value) {zcert_set_meta(self, key, "%s", value);}
*/
import "C"
import (
"fmt"
"os"
"unsafe"
)
// Cert wraps the CZMQ zcert class. It provides tools for
// creating and working with ZMQ CURVE security certs.
// The certs can be used as a temporary object in memory
// or persisted to disk. Certs are made up of a public
// and secret keypair + metadata.
type Cert struct {
zcertT *C.struct__zcert_t
}
// NewCert creates a new empty Cert instance
func NewCert() *Cert {
return &Cert{
zcertT: C.zcert_new(),
}
}
// NewCertFromKeys creates a new Cert from a public and private key
func NewCertFromKeys(public []byte, secret []byte) (*Cert, error) {
if len(public) != 32 {
return nil, fmt.Errorf("invalid public key")
}
if len(secret) != 32 {
return nil, fmt.Errorf("invalid private key")
}
return &Cert{
zcertT: C.zcert_new_from(
(*C.byte)(unsafe.Pointer(&public[0])),
(*C.byte)(unsafe.Pointer(&secret[0]))),
}, nil
}
// NewCertFromFile Load loads a Cert from files
func NewCertFromFile(filename string) (*Cert, error) {
_, err := os.Stat(filename)
if os.IsNotExist(err) {
return nil, ErrCertNotFound
}
cFilename := C.CString(filename)
defer C.free(unsafe.Pointer(cFilename))
cert := C.zcert_load(cFilename)
return &Cert{
zcertT: cert,
}, nil
}
// SetMeta sets meta data for a Cert
func (c *Cert) SetMeta(key string, value string) {
cKey := C.CString(key)
defer C.free(unsafe.Pointer(cKey))
cValue := C.CString(value)
defer C.free(unsafe.Pointer(cValue))
C.Set_meta(c.zcertT, cKey, cValue)
}
// Meta returns a meta data item from a Cert given a key
func (c *Cert) Meta(key string) string {
cKey := C.CString(key)
defer C.free(unsafe.Pointer(cKey))
val := C.zcert_meta(c.zcertT, cKey)
return C.GoString(val)
}
// PublicText returns the public key as a string
func (c *Cert) PublicText() string {
val := C.zcert_public_txt(c.zcertT)
return C.GoString(val)
}
// Apply sets the public and private keys for a socket
func (c *Cert) Apply(s *Sock) {
handle := C.zsock_resolve(unsafe.Pointer(s.zsockT))
C.zsock_set_curve_secretkey_bin(handle, C.zcert_secret_key(c.zcertT))
C.zsock_set_curve_publickey_bin(handle, C.zcert_public_key(c.zcertT))
}
// Dup duplicates a Cert
func (c *Cert) Dup() *Cert {
return &Cert{
zcertT: C.zcert_dup(c.zcertT),
}
}
// Equal checks two Certs for equality
func (c *Cert) Equal(compare *Cert) bool {
check := C.zcert_eq(c.zcertT, compare.zcertT)
if check == C.bool(true) {
return true
}
return false
}
// Print prints a Cert to stdout
func (c *Cert) Print() {
C.zcert_print(c.zcertT)
}
// SavePublic saves the public key to a file
func (c *Cert) SavePublic(filename string) error {
cFilename := C.CString(filename)
defer C.free(unsafe.Pointer(cFilename))
rc := C.zcert_save_public(c.zcertT, cFilename)
if rc == C.int(-1) {
return fmt.Errorf("SavePublic error")
}
return nil
}
// SaveSecret saves the secret key to a file
func (c *Cert) SaveSecret(filename string) error {
cFilename := C.CString(filename)
defer C.free(unsafe.Pointer(cFilename))
rc := C.zcert_save_secret(c.zcertT, cFilename)
if rc == C.int(-1) {
return fmt.Errorf("SaveSecret error")
}
return nil
}
// Save saves the public and secret key to filename and filename_secret
func (c *Cert) Save(filename string) error {
cFilename := C.CString(filename)
defer C.free(unsafe.Pointer(cFilename))
rc := C.zcert_save(c.zcertT, cFilename)
if rc == C.int(-1) {
return fmt.Errorf("SavePublic: error")
}
return nil
}
// Destroy destroys Cert instance
func (c *Cert) Destroy() {
C.zcert_destroy(&c.zcertT)
}

60
vendor/gopkg.in/zeromq/goczmq.v4/certstore.go generated vendored Normal file
View File

@ -0,0 +1,60 @@
package goczmq
/*
#include "czmq.h"
*/
import "C"
import
// CertStore works with directories of CURVE security certificates.
// It lets you easily load stores from disk and check if a key
// is present or not. This could be done fairly easily in pure
// Go, but is included for the sake of compatibility.
"unsafe"
type CertStore struct {
zcertstoreT *C.struct__zcertstore_t
}
// NewCertStore creates a new certificate store from
// a disk directory, loading and indexing all certificates.
func NewCertStore(location string) *CertStore {
cLocation := C.CString(location)
defer C.free(unsafe.Pointer(cLocation))
return &CertStore{
zcertstoreT: C.zcertstore_new(cLocation),
}
}
// Insert inserts a certificate into the store in memory.
// Call Save directly on the cert if you wish to save it
// to disk.
func (c *CertStore) Insert(cert *Cert) {
C.zcertstore_insert(c.zcertstoreT, &cert.zcertT)
}
// Lookup looks up a certificate in the store by public key and
// returns it.
func (c *CertStore) Lookup(key string) *Cert {
cKey := C.CString(key)
defer C.free(unsafe.Pointer(cKey))
ptr := C.zcertstore_lookup(c.zcertstoreT, cKey)
if ptr == nil {
return nil
}
return &Cert{
zcertT: ptr,
}
}
// Print prints a list of certificates in the store to stdout
func (c *CertStore) Print() {
C.zcertstore_print(c.zcertstoreT)
}
// Destroy destroys Cert instance
func (c *CertStore) Destroy() {
C.zcertstore_destroy(&c.zcertstoreT)
}

309
vendor/gopkg.in/zeromq/goczmq.v4/channeler.go generated vendored Normal file
View File

@ -0,0 +1,309 @@
package goczmq
/*
#include "czmq.h"
void Sock_init() {zsys_init();}
*/
import "C"
import (
"fmt"
"math/rand"
"strings"
)
// Channeler serializes all access to a socket through a send
// and receive channel. It starts two threads, on is used for receiving
// from the zeromq socket. The other is used to listen to the receive
// channel, and send everything back to the socket thrad for sending
// using an additional inproc socket.
type Channeler struct {
id int64
sockType int
endpoints string
subscribe *string
commandAddr string
proxyAddr string
commandChan chan<- string
SendChan chan<- [][]byte
RecvChan <-chan [][]byte
}
// Destroy sends a message to the Channeler to shut it down
// and clean it up.
func (c *Channeler) Destroy() {
c.commandChan <- "destroy"
}
// Subscribe to a Topic
func (c *Channeler) Subscribe(topic string) {
c.commandChan <- fmt.Sprintf("subscribe %s", topic)
}
// Unsubscribe from a Topic
func (c *Channeler) Unsubscribe(topic string) {
c.commandChan <- fmt.Sprintf("unsubscribe %s", topic)
}
// actor is a routine that handles communication with
// the zeromq socket.
func (c *Channeler) actor(recvChan chan<- [][]byte) {
pipe, err := NewPair(fmt.Sprintf(">%s", c.commandAddr))
if err != nil {
panic(err)
}
defer pipe.Destroy()
defer close(recvChan)
pull, err := NewPull(c.proxyAddr)
if err != nil {
panic(err)
}
defer pull.Destroy()
sock := NewSock(c.sockType)
defer sock.Destroy()
switch c.sockType {
case Pub, Rep, Pull, Router, XPub:
err = sock.Attach(c.endpoints, true)
if err != nil {
panic(err)
}
case Req, Push, Dealer, Pair, Stream, XSub:
err = sock.Attach(c.endpoints, false)
if err != nil {
panic(err)
}
case Sub:
if c.subscribe != nil {
subscriptions := strings.Split(*c.subscribe, ",")
for _, topic := range subscriptions {
sock.SetSubscribe(topic)
}
}
err = sock.Attach(c.endpoints, false)
if err != nil {
panic(err)
}
default:
panic(ErrInvalidSockType)
}
poller, err := NewPoller(sock, pull, pipe)
if err != nil {
panic(err)
}
defer poller.Destroy()
for {
s := poller.Wait(-1)
switch s {
case pipe:
cmd, err := pipe.RecvMessage()
if err != nil {
panic(err)
}
switch string(cmd[0]) {
case "destroy":
disconnect := strings.Split(c.endpoints, ",")
for _, endpoint := range disconnect {
sock.Disconnect(endpoint)
}
pipe.SendMessage([][]byte{[]byte("ok")})
goto ExitActor
case "subscribe":
topic := string(cmd[1])
sock.SetSubscribe(topic)
pipe.SendMessage([][]byte{[]byte("ok")})
case "unsubscribe":
topic := string(cmd[1])
sock.SetUnsubscribe(topic)
pipe.SendMessage([][]byte{[]byte("ok")})
}
case sock:
msg, err := s.RecvMessage()
if err != nil {
panic(err)
}
recvChan <- msg
case pull:
msg, err := pull.RecvMessage()
if err != nil {
panic(err)
}
err = sock.SendMessage(msg)
if err != nil {
panic(err)
}
}
}
ExitActor:
}
// channeler is a routine that handles the channel select loop
// and sends commands to the zeromq socket.
func (c *Channeler) channeler(commandChan <-chan string, sendChan <-chan [][]byte) {
push, err := NewPush(c.proxyAddr)
if err != nil {
panic(err)
}
defer push.Destroy()
pipe, err := NewPair(fmt.Sprintf("@%s", c.commandAddr))
if err != nil {
panic(err)
}
defer pipe.Destroy()
for {
select {
case cmd := <-commandChan:
switch cmd {
case "destroy":
err = pipe.SendFrame([]byte("destroy"), FlagNone)
if err != nil {
panic(err)
}
_, err = pipe.RecvMessage()
if err != nil {
panic(err)
}
goto ExitChanneler
default:
parts := strings.Split(cmd, " ")
numParts := len(parts)
message := make([][]byte, numParts, numParts)
for i, p := range parts {
message[i] = []byte(p)
}
err := pipe.SendMessage(message)
if err != nil {
panic(err)
}
_, err = pipe.RecvMessage()
if err != nil {
panic(err)
}
}
case msg := <-sendChan:
err := push.SendMessage(msg)
if err != nil {
panic(err)
}
}
}
ExitChanneler:
}
// newChanneler accepts arguments from the socket type based
// constructors and creates a new Channeler instance
func newChanneler(sockType int, endpoints string, subscribe ...string) *Channeler {
commandChan := make(chan string)
sendChan := make(chan [][]byte)
recvChan := make(chan [][]byte)
C.Sock_init()
c := &Channeler{
id: rand.Int63(),
endpoints: endpoints,
sockType: sockType,
commandChan: commandChan,
SendChan: sendChan,
RecvChan: recvChan,
}
c.commandAddr = fmt.Sprintf("inproc://actorcontrol%d", c.id)
c.proxyAddr = fmt.Sprintf("inproc://proxy%d", c.id)
if len(subscribe) > 0 {
topics := strings.Join(subscribe, ",")
c.subscribe = &topics
}
go c.channeler(commandChan, sendChan)
go c.actor(recvChan)
return c
}
// NewPubChanneler creats a new Channeler wrapping
// a Pub socket. The socket will bind by default.
func NewPubChanneler(endpoints string) *Channeler {
return newChanneler(Pub, endpoints, "")
}
// NewSubChanneler creates a new Channeler wrapping
// a Sub socket. Along with an endpoint list
// it accepts a comma delimited list of topics.
// The socket will connect by default.
func NewSubChanneler(endpoints string, subscribe ...string) *Channeler {
return newChanneler(Sub, endpoints, subscribe...)
}
// NewRepChanneler creates a new Channeler wrapping
// a Rep socket. The socket will bind by default.
func NewRepChanneler(endpoints string) *Channeler {
return newChanneler(Rep, endpoints, "")
}
// NewReqChanneler creates a new Channeler wrapping
// a Req socket. The socket will connect by default.
func NewReqChanneler(endpoints string) *Channeler {
return newChanneler(Req, endpoints, "")
}
// NewPullChanneler creates a new Channeler wrapping
// a Pull socket. The socket will bind by default.
func NewPullChanneler(endpoints string) *Channeler {
return newChanneler(Pull, endpoints, "")
}
// NewPushChanneler creates a new Channeler wrapping
// a Push socket. The socket will connect by default.
func NewPushChanneler(endpoints string) *Channeler {
return newChanneler(Push, endpoints, "")
}
// NewRouterChanneler creates a new Channeler wrapping
// a Router socket. The socket will Bind by default.
func NewRouterChanneler(endpoints string) *Channeler {
return newChanneler(Router, endpoints, "")
}
// NewDealerChanneler creates a new Channeler wrapping
// a Dealer socket. The socket will connect by default.
func NewDealerChanneler(endpoints string) *Channeler {
return newChanneler(Dealer, endpoints, "")
}
// NewXPubChanneler creates a new Channeler wrapping
// an XPub socket. The socket will Bind by default.
func NewXPubChanneler(endpoints string) *Channeler {
return newChanneler(XPub, endpoints, "")
}
// NewXSubChanneler creates a new Channeler wrapping
// a XSub socket. The socket will connect by default.
func NewXSubChanneler(endpoints string) *Channeler {
return newChanneler(XSub, endpoints, "")
}
// NewPairChanneler creates a new Channeler wrapping
// a Pair socket. The socket will connect by default.
func NewPairChanneler(endpoints string) *Channeler {
return newChanneler(Pair, endpoints, "")
}
// NewStreamChanneler creates a new Channeler wrapping
// a Pair socket. The socket will connect by default.
func NewStreamChanneler(endpoints string) *Channeler {
return newChanneler(Stream, endpoints, "")
}

201
vendor/gopkg.in/zeromq/goczmq.v4/goczmq.go generated vendored Normal file
View File

@ -0,0 +1,201 @@
// Package goczmq is a golang binding for CZMQ 3. CZMQ is a high level binding
// for ZeroMQ. Along with ZeroMQ socket support, CZMQ provides "actor" based
// services for authentication, service discovery, and creating proxies.
// GoCZMQ provides direct bindings to CZMQ along with higher level go
// abstractions such as channels and io.ReadWriter interface support.
//
// "Tell them I was a writer.
// A maker of software.
// A humanist. A father.
// And many things.
// But above all, a writer.
// Thank You. :)
// - Pieter Hintjens
package goczmq
/*
#cgo !windows pkg-config: libczmq libzmq libsodium
#cgo windows LDFLAGS: -lws2_32 -liphlpapi -lrpcrt4 -lsodium -lzmq -lczmq
#cgo windows CFLAGS: -Wno-pedantic-ms-format -DLIBCZMQ_EXPORTS -DZMQ_DEFINED_STDINT -DLIBCZMQ_EXPORTS -DZMQ_BUILD_DRAFT_API
#include "czmq.h"
#include <stdlib.h>
#include <string.h>
*/
import "C"
import (
"errors"
)
const (
// Req is a ZMQ_REQ socket type
Req = int(C.ZMQ_REQ)
// Rep is a ZMQ_REP socket type
Rep = int(C.ZMQ_REP)
// Dealer is a ZMQ_DEALER socket type
Dealer = int(C.ZMQ_DEALER)
// Router is a ZMQ_ROUTER socket type
Router = int(C.ZMQ_ROUTER)
// Pub is a ZMQ_PUB socket type
Pub = int(C.ZMQ_PUB)
// Sub is a ZMQ_SUB socket type
Sub = int(C.ZMQ_SUB)
// XPub is a ZMQ_XPUB socket type
XPub = int(C.ZMQ_XPUB)
// XSub is a ZMQ_XSUB socket type
XSub = int(C.ZMQ_XSUB)
// Push is a ZMQ_PUSH socket type
Push = int(C.ZMQ_PUSH)
// Pull is a ZMQ_PULL socket type
Pull = int(C.ZMQ_PULL)
// Pair is a ZMQ_PAIR socket type
Pair = int(C.ZMQ_PAIR)
// Stream is a ZMQ_STREAM socket type
Stream = int(C.ZMQ_STREAM)
// Pollin is the ZMQ_POLLIN constant
Pollin = int(C.ZMQ_POLLIN)
// Pollout is the ZMQ_POLLOUT constant
Pollout = int(C.ZMQ_POLLOUT)
// FlagMore is the ZFRAME_MORE flag
FlagMore = int(C.ZFRAME_MORE)
// FlagReuse is the ZFRAME_REUSE flag
FlagReuse = int(C.ZFRAME_REUSE)
//FlagDontWait is the ZFRAME_DONTWAIT flag
FlagDontWait = int(C.ZFRAME_DONTWAIT)
//FlagNone means there are no flags
FlagNone = 0
// CurveAllowAny is a semantic convenience for allowing
// any Curve clients
CurveAllowAny = "*"
//ZMQVersionMajor is the major version of the underlying ZeroMQ library
ZMQVersionMajor = int(C.ZMQ_VERSION_MAJOR)
//ZMQVersionMinor is the minor version of the underlying ZeroMQ library
ZMQVersionMinor = int(C.ZMQ_VERSION_MINOR)
//CZMQVersionMajor is the major version of the underlying CZMQ library
CZMQVersionMajor = int(C.CZMQ_VERSION_MAJOR)
// CZMQVersionMinor is the minor version of the underlying CZMQ library
CZMQVersionMinor = int(C.CZMQ_VERSION_MINOR)
)
var (
// ErrActorCmd is returned when there is an error sending
// a command to an actor
ErrActorCmd = errors.New("error sending actor command")
// ErrSockAttach is returned when an attach call to a socket fails
ErrSockAttach = errors.New("error attaching zsock")
// ErrInvalidSockType is returned when a function is called
// against a socket type that is not applicable for that socket type
ErrInvalidSockType = errors.New("invalid socket type")
// ErrSliceFull is returned if a []byte passed to Read was not
// large enough to hold the contents of a message
ErrSliceFull = errors.New("slice full")
// ErrConnect is returned if Connect on a socket fails
ErrConnect = errors.New("connect error")
// ErrDisconnect is returned if Disconnect on a socket fails
ErrDisconnect = errors.New("disconnect error")
// ErrBind is returned if Bind on a socket fails
ErrBind = errors.New("bind error")
// ErrUnbind is returned if Unbind on a socket fails
ErrUnbind = errors.New("unbind error")
// ErrSendFrame is returned if SendFrame on a socket fails
ErrSendFrame = errors.New("send frame error")
// ErrRecvFrame is returned if RecvFrame on a socket fails
ErrRecvFrame = errors.New("recv frame error")
// ErrRecvFrameAfterDestroy is returned if RecvFrame is called
// on a socket after it has been destroyed.
ErrRecvFrameAfterDestroy = errors.New("RecvFrame() is invalid on socket after Detroy() has been called.")
// ErrRecvMessage is returned if RecvMessage on a socket fails
ErrRecvMessage = errors.New("recv message error")
// ErrWaitAfterDestroy is returned by a Poller if there is an error
// accessing the underlying socket pointer when Wait is called
ErrWaitAfterDestroy = errors.New("Wait() is invalid on Poller after Destroy() is called.")
// ErrMultiPartUnsupported is returned when a function that does
// not support multi-part messages encounters a multi-part message
ErrMultiPartUnsupported = errors.New("function does not support multi part messages")
// ErrTimeout is returned when a function that supports timeouts times out
ErrTimeout = errors.New("function timed out")
// ErrCertNotFound is returned when NewCertFromFile tries to
// load a file that does not exist.
ErrCertNotFound = errors.New("file not found")
)
// Shutdown shuts down the CZMQ zsys layer.
// The CZMQ zsys layer normally shuts down on process termination through the
// use of an atexit cleanup function. Calling this allows the zsys layer to be
// shutdown manually.
//
// This is beneficial when CZMQ will no longer be used but the process will not
// be terminating. Any potential resources allocated by the zsys layer can be
// freed as they will no longer be needed.
func Shutdown() {
C.zsys_shutdown()
}
func getStringType(k int) string {
switch k {
case Req:
return "REQ"
case Rep:
return "REP"
case Dealer:
return "DEALER"
case Router:
return "ROUTER"
case Pub:
return "PUB"
case Sub:
return "SUB"
case XPub:
return "XPUB"
case XSub:
return "XSUB"
case Push:
return "PUSH"
case Pull:
return "PULL"
case Pair:
return "PAIR"
case Stream:
return "STREAM"
default:
return ""
}
}

22
vendor/gopkg.in/zeromq/goczmq.v4/license.xml generated vendored Normal file
View File

@ -0,0 +1,22 @@
<license>
Copyright (C) 2014 the Authors
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.
</license>

106
vendor/gopkg.in/zeromq/goczmq.v4/poller.go generated vendored Normal file
View File

@ -0,0 +1,106 @@
package goczmq
/*
#include "czmq.h"
zpoller_t *Poller_new(void *reader) {
zpoller_t *poller = zpoller_new(reader, NULL);
return poller;
}
*/
import "C"
import (
"fmt"
"unsafe"
)
// Poller provides a simple wrapper to ZeroMQ's zmq_poll API,
// for the common case of reading from a number of sockets.
// Sockets can be added and removed from the running poller.
type Poller struct {
zpollerT *C.struct__zpoller_t
socks []*Sock
}
// NewPoller creates a new Poller instance.
// It accepts one or more readers to poll.
func NewPoller(readers ...*Sock) (*Poller, error) {
var p *Poller
if len(readers) == 0 {
p = &Poller{
zpollerT: C.Poller_new(nil),
socks: make([]*Sock, 0),
}
} else {
p = &Poller{
zpollerT: C.Poller_new(unsafe.Pointer(readers[0].zsockT)),
socks: make([]*Sock, 0),
}
p.socks = append(p.socks, readers[0])
if len(readers) == 1 {
return p, nil
}
for _, reader := range readers[1:] {
err := p.Add(reader)
if err != nil {
return nil, err
}
}
}
return p, nil
}
// Add adds a reader to be polled.
func (p *Poller) Add(reader *Sock) error {
rc := C.zpoller_add(p.zpollerT, unsafe.Pointer(reader.zsockT))
if int(rc) == -1 {
return fmt.Errorf("error adding reader")
}
p.socks = append(p.socks, reader)
return nil
}
// Remove removes a Sock from the poller
func (p *Poller) Remove(reader *Sock) {
numItems := len(p.socks)
for i := 0; i < numItems; i++ {
if p.socks[i] == reader {
if i == numItems-1 {
p.socks = p.socks[:i]
} else {
p.socks = append(p.socks[:i], p.socks[i+1:]...)
}
}
}
}
// Wait waits for the timeout period in milliseconds for a Pollin
// event, and returns the first socket that returns one
func (p *Poller) Wait(millis int) *Sock {
if p.zpollerT == nil {
// Null pointer. Something is wrong or we've already had `Destroy` invoked on us.
panic(ErrWaitAfterDestroy)
}
s := C.zpoller_wait(p.zpollerT, C.int(millis))
s = unsafe.Pointer(s)
if s == nil {
return nil
}
for _, sock := range p.socks {
if unsafe.Pointer(sock.zsockT) == s {
return sock
}
}
panic(fmt.Sprintf(
"Could not match received pointer with %v with any socket (%v)",
s, p.socks))
}
// Destroy destroys the Poller
func (p *Poller) Destroy() {
C.zpoller_destroy(&p.zpollerT)
}

171
vendor/gopkg.in/zeromq/goczmq.v4/proxy.go generated vendored Normal file
View File

@ -0,0 +1,171 @@
package goczmq
/*
#include "czmq.h"
zactor_t *Zproxy_new () {
zactor_t *proxy = zactor_new(zproxy, NULL);
return proxy;
}
*/
import "C"
import (
"unsafe"
)
// Proxy wraps the CZMQ zproxy actor. A proxy actor switches
// messages between a frontend and backend socket, and also
// provides an optional capture socket messages can be
// mirrored to. The proxy can be paused and resumed.
type Proxy struct {
zactorT *C.struct__zactor_t
}
// NewProxy creates a new Proxy instance.
func NewProxy() *Proxy {
p := &Proxy{}
p.zactorT = C.Zproxy_new()
return p
}
// SetFrontend accepts a socket type and endpoint, and sends a message
// to the zactor thread telling it to set up a socket bound to the endpoint.
func (p *Proxy) SetFrontend(sockType int, endpoint string) error {
typeString := getStringType(sockType)
cmd := C.CString("FRONTEND")
defer C.free(unsafe.Pointer(cmd))
cTypeString := C.CString(typeString)
defer C.free(unsafe.Pointer(cTypeString))
cEndpoint := C.CString(endpoint)
defer C.free(unsafe.Pointer(cEndpoint))
rc := C.zstr_sendm(unsafe.Pointer(p.zactorT), cmd)
if rc == -1 {
return ErrActorCmd
}
rc = C.zstr_sendm(unsafe.Pointer(p.zactorT), cTypeString)
if rc == -1 {
return ErrActorCmd
}
rc = C.zstr_send(unsafe.Pointer(p.zactorT), cEndpoint)
if rc == -1 {
return ErrActorCmd
}
rc = C.zsock_wait(unsafe.Pointer(p.zactorT))
if rc == -1 {
return ErrActorCmd
}
return nil
}
// SetBackend accepts a socket type and endpoint, and sends a message
// to the zactor thread telling it to set up a socket bound to the endpoint.
func (p *Proxy) SetBackend(sockType int, endpoint string) error {
typeString := getStringType(sockType)
cmd := C.CString("BACKEND")
defer C.free(unsafe.Pointer(cmd))
cTypeString := C.CString(typeString)
defer C.free(unsafe.Pointer(cTypeString))
cEndpoint := C.CString(endpoint)
defer C.free(unsafe.Pointer(cEndpoint))
rc := C.zstr_sendm(unsafe.Pointer(p.zactorT), cmd)
if rc == -1 {
return ErrActorCmd
}
rc = C.zstr_sendm(unsafe.Pointer(p.zactorT), cTypeString)
if rc == -1 {
return ErrActorCmd
}
rc = C.zstr_send(unsafe.Pointer(p.zactorT), cEndpoint)
if rc == -1 {
return ErrActorCmd
}
rc = C.zsock_wait(unsafe.Pointer(p.zactorT))
if rc == -1 {
return ErrActorCmd
}
return nil
}
// SetCapture accepts a socket endpoint and sets up a Push socket bound
// to that endpoint, that sends a copy of all messages passing through
// the proxy.
func (p *Proxy) SetCapture(endpoint string) error {
cmd := C.CString("CAPTURE")
defer C.free(unsafe.Pointer(cmd))
cEndpoint := C.CString(endpoint)
defer C.free(unsafe.Pointer(cEndpoint))
rc := C.zstr_sendm(unsafe.Pointer(p.zactorT), cmd)
if rc == -1 {
return ErrActorCmd
}
rc = C.zstr_send(unsafe.Pointer(p.zactorT), cEndpoint)
if rc == -1 {
return ErrActorCmd
}
return nil
}
// Pause sends a message to the zproxy actor telling it to pause.
func (p *Proxy) Pause() error {
cmd := C.CString("PAUSE")
defer C.free(unsafe.Pointer(cmd))
rc := C.zstr_send(unsafe.Pointer(p.zactorT), cmd)
if rc == -1 {
return ErrActorCmd
}
return nil
}
// Resume sends a message to the zproxy actor telling it to resume.
func (p *Proxy) Resume() error {
cmd := C.CString("RESUME")
defer C.free(unsafe.Pointer(cmd))
rc := C.zstr_send(unsafe.Pointer(p.zactorT), cmd)
if rc == -1 {
return ErrActorCmd
}
return nil
}
// Verbose sets the proxy to log information to stdout.
func (p *Proxy) Verbose() error {
cmd := C.CString("VERBOSE")
defer C.free(unsafe.Pointer(cmd))
rc := C.zstr_send(unsafe.Pointer(p.zactorT), cmd)
if rc == -1 {
return ErrActorCmd
}
return nil
}
// Destroy destroys the proxy.
func (p *Proxy) Destroy() {
C.zactor_destroy(&p.zactorT)
}

120
vendor/gopkg.in/zeromq/goczmq.v4/readwriter.go generated vendored Normal file
View File

@ -0,0 +1,120 @@
package goczmq
import (
"C"
"io"
)
// ReadWriter provides an io.ReadWriter compatible
// interface for goczmq.Sock
type ReadWriter struct {
sock *Sock
poller *Poller
clientIDs []string
frame []byte
currentIndex int
timeoutMillis int
}
// NewReadWriter accepts a sock and returns a goczmq.ReadWriter. The
// io.ReadWriter should now be considered responsible for this
// Sock.
func NewReadWriter(sock *Sock) (*ReadWriter, error) {
rw := &ReadWriter{
sock: sock,
timeoutMillis: -1,
}
var err error
rw.poller, err = NewPoller(rw.sock)
return rw, err
}
// SetTimeout sets the timeout on Read in millisecond. If no new
// data is received within the timeout period, Read will return
// an ErrTimeout
func (r *ReadWriter) SetTimeout(ms int) {
r.timeoutMillis = ms
}
// Read satisifies io.Read
func (r *ReadWriter) Read(p []byte) (int, error) {
var totalRead int
var totalFrame int
var flag int
var err error
if r.currentIndex == 0 {
s := r.poller.Wait(r.timeoutMillis)
if s == nil {
return totalRead, ErrTimeout
}
r.frame, flag, err = s.RecvFrame()
if s.GetType() == Router && r.currentIndex == 0 {
r.clientIDs = append(r.clientIDs, string(r.frame))
r.frame, flag, err = s.RecvFrame()
}
if flag == FlagMore {
return totalRead, ErrMultiPartUnsupported
}
if err != nil {
return totalRead, io.EOF
}
}
totalRead += copy(p[:], r.frame[r.currentIndex:])
totalFrame += len(r.frame)
if totalFrame-r.currentIndex > len(p) {
r.currentIndex = totalRead
} else {
r.currentIndex = 0
err = io.EOF
}
return totalRead, err
}
// Write satisfies io.Write
func (r *ReadWriter) Write(p []byte) (int, error) {
var total int
if r.sock.GetType() == Router {
err := r.sock.SendFrame(r.GetLastClientID(), FlagMore)
if err != nil {
return total, err
}
}
err := r.sock.SendFrame(p, 0)
if err != nil {
return total, err
}
return len(p), nil
}
// GetLastClientID returns the id of the last client you received
// a message from if the underlying socket is a Router socket
func (r *ReadWriter) GetLastClientID() []byte {
id := []byte(r.clientIDs[0])
r.clientIDs = r.clientIDs[1:]
return id
}
// SetLastClientID lets you manually set the id of the client
// you last received a message from if the underlying socket
// is a Router socket
func (r *ReadWriter) SetLastClientID(id []byte) {
r.clientIDs = append(r.clientIDs, string(id))
}
// Destroy destroys both the ReadWriter and the underlying Sock
func (r *ReadWriter) Destroy() {
r.sock.Destroy()
r.poller.Destroy()
}

435
vendor/gopkg.in/zeromq/goczmq.v4/sock.go generated vendored Normal file
View File

@ -0,0 +1,435 @@
package goczmq
/*
#include "czmq.h"
#include <stdlib.h>
#include <string.h>
int Sock_connect(zsock_t *self, const char *format) {return zsock_connect(self, format, NULL);}
int Sock_disconnect(zsock_t *self, const char *format) {return zsock_disconnect(self, format, NULL);}
int Sock_bind(zsock_t *self, const char *format) {return zsock_bind(self, format, NULL);}
int Sock_unbind(zsock_t *self, const char *format) {return zsock_unbind(self, format, NULL);}
int Sock_sendframe(zsock_t *sock, const void *data, size_t size, int flags) {
zframe_t *frame = zframe_new (data, size);
int rc = zframe_send (&frame, sock, flags);
return rc;
}
*/
import "C"
import (
"os"
"runtime"
"strings"
"unsafe"
)
// Sock wraps the CZMQ zsock class.
type Sock struct {
zsockT *C.struct__zsock_t
file string
line int
zType int
clientIDs []string
}
func init() {
if err := os.Setenv("ZSYS_SIGHANDLER", "false"); err != nil {
panic(err)
}
}
// GetLastClientID returns the id of the last client you received
// a message from if the underlying socket is a Router socket
// DEPRECATED: See goczmq.ReadWriter
func (s *Sock) GetLastClientID() []byte {
id := []byte(s.clientIDs[0])
s.clientIDs = s.clientIDs[1:]
return id
}
// SetLastClientID lets you manually set the id of the client
// you last received a message from if the underlying socket
// is a Router socket
// DEPRECATED: See goczmq.ReadWriter
func (s *Sock) SetLastClientID(id []byte) {
s.clientIDs = append(s.clientIDs, string(id))
}
// NewSock creates a new socket. The caller source and
// line number are passed so CZMQ can report socket leaks
// intelligently.
func NewSock(t int) *Sock {
var s *Sock
_, file, line, ok := runtime.Caller(1)
if ok {
s = &Sock{
file: file,
line: line,
zType: t,
clientIDs: make([]string, 0),
}
} else {
s = &Sock{
file: "",
line: 0,
zType: t,
clientIDs: make([]string, 0),
}
}
cFile := C.CString(s.file)
defer C.free(unsafe.Pointer(cFile))
s.zsockT = C.zsock_new_checked(C.int(s.zType), cFile, C.size_t(s.line))
return s
}
// Connect connects a socket to an endpoint
// returns an error if the connect failed.
func (s *Sock) Connect(endpoint string) error {
cEndpoint := C.CString(endpoint)
defer C.free(unsafe.Pointer(cEndpoint))
rc := C.Sock_connect(s.zsockT, cEndpoint)
if rc != C.int(0) {
return ErrConnect
}
return nil
}
// Disconnect disconnects a socket from an endpoint. If returns
// an error if the endpoint was not found
func (s *Sock) Disconnect(endpoint string) error {
cEndpoint := C.CString(endpoint)
defer C.free(unsafe.Pointer(cEndpoint))
rc := C.Sock_disconnect(s.zsockT, cEndpoint)
if int(rc) == -1 {
return ErrDisconnect
}
return nil
}
// Bind binds a socket to an endpoint. On success returns
// the port number used for tcp transports, or 0 for other
// transports. On failure returns a -1 for port, and an error.
func (s *Sock) Bind(endpoint string) (int, error) {
cEndpoint := C.CString(endpoint)
defer C.free(unsafe.Pointer(cEndpoint))
port := C.Sock_bind(s.zsockT, cEndpoint)
if port == C.int(-1) {
return -1, ErrBind
}
return int(port), nil
}
// Unbind unbinds a socket from an endpoint. If returns
// an error if the endpoint was not found
func (s *Sock) Unbind(endpoint string) error {
cEndpoint := C.CString(endpoint)
defer C.free(unsafe.Pointer(cEndpoint))
rc := C.Sock_unbind(s.zsockT, cEndpoint)
if int(rc) == -1 {
return ErrUnbind
}
return nil
}
// Attach attaches a socket to zero or more endpoints. If endpoints is not null,
// parses as list of ZeroMQ endpoints, separated by commas, and prefixed by
// '@' (to bind the socket) or '>' (to attach the socket). If the endpoint
// does not start with '@' or '>', the serverish argument determines whether
// it is used to bind (serverish = true) or connect (serverish = false)
func (s *Sock) Attach(endpoints string, serverish bool) error {
cEndpoints := C.CString(endpoints)
defer C.free(unsafe.Pointer(cEndpoints))
rc := C.zsock_attach(s.zsockT, cEndpoints, C._Bool(serverish))
if rc == -1 {
return ErrSockAttach
}
return nil
}
// NewPub creates a Pub socket and calls Attach.
// The socket will Bind by default.
func NewPub(endpoints string) (*Sock, error) {
s := NewSock(Pub)
return s, s.Attach(endpoints, true)
}
// NewSub creates a Sub socket and calls Attach.
// 'subscribe' is a comma delimited list of topics to subscribe to.
// The socket will Connect by default.
func NewSub(endpoints string, subscribe string) (*Sock, error) {
s := NewSock(Sub)
subscriptions := strings.Split(subscribe, ",")
for _, topic := range subscriptions {
s.SetSubscribe(topic)
}
return s, s.Attach(endpoints, false)
}
// NewRep creates a Rep socket and calls Attach.
// The socket will Bind by default.
func NewRep(endpoints string) (*Sock, error) {
s := NewSock(Rep)
return s, s.Attach(endpoints, true)
}
// NewReq creates a Req socket and calls Attach.
// The socket will Connect by default.
func NewReq(endpoints string) (*Sock, error) {
s := NewSock(Req)
return s, s.Attach(endpoints, false)
}
// NewPull creates a Pull socket and calls Attach.
// The socket will Bind by default.
func NewPull(endpoints string) (*Sock, error) {
s := NewSock(Pull)
return s, s.Attach(endpoints, true)
}
// NewPush creates a Push socket and calls Attach.
// The socket will Connect by default.
func NewPush(endpoints string) (*Sock, error) {
s := NewSock(Push)
return s, s.Attach(endpoints, false)
}
// NewRouter creates a Router socket and calls Attach.
// The socket will Bind by default.
func NewRouter(endpoints string) (*Sock, error) {
s := NewSock(Router)
return s, s.Attach(endpoints, true)
}
// NewDealer creates a Dealer socket and calls Attach.
// The socket will Connect by default.
func NewDealer(endpoints string) (*Sock, error) {
s := NewSock(Dealer)
return s, s.Attach(endpoints, false)
}
// NewXPub creates an XPub socket and calls Attach.
// The socket will Bind by default.
func NewXPub(endpoints string) (*Sock, error) {
s := NewSock(XPub)
return s, s.Attach(endpoints, true)
}
// NewXSub creates an XSub socket and calls Attach.
// The socket will Connect by default.
func NewXSub(endpoints string) (*Sock, error) {
s := NewSock(XSub)
return s, s.Attach(endpoints, false)
}
// NewPair creates a Pair socket and calls Attach.
// The socket will Connect by default.
func NewPair(endpoints string) (*Sock, error) {
s := NewSock(Pair)
return s, s.Attach(endpoints, false)
}
// NewStream creates a Stream socket and calls Attach.
// The socket will Connect by default.
func NewStream(endpoints string) (*Sock, error) {
s := NewSock(Stream)
return s, s.Attach(endpoints, false)
}
// Pollin returns true if there is a Pollin
// event on the socket
func (s *Sock) Pollin() bool {
return s.Events() == Pollin
}
// Pollout returns true if there is a Pollout
// event on the socket
func (s *Sock) Pollout() bool {
return s.Events() == Pollout
}
// SendFrame sends a byte array via the socket. For the flags
// value, use 0 for a single message, or SNDFlagMore if it is
// a multi-part message
func (s *Sock) SendFrame(data []byte, flags int) error {
var rc C.int
if len(data) == 0 {
rc = C.Sock_sendframe(s.zsockT, nil, C.size_t(0), C.int(flags))
} else {
rc = C.Sock_sendframe(s.zsockT, unsafe.Pointer(&data[0]), C.size_t(len(data)), C.int(flags))
}
if rc == C.int(-1) {
return ErrSendFrame
}
return nil
}
// RecvFrame reads a frame from the socket and returns it
// as a byte array, along with a more flag and and error
// (if there is an error)
func (s *Sock) RecvFrame() ([]byte, int, error) {
if s.zsockT == nil {
return nil, -1, ErrRecvFrameAfterDestroy
}
frame := C.zframe_recv(unsafe.Pointer(s.zsockT))
if frame == nil {
return []byte{0}, 0, ErrRecvFrame
}
dataSize := C.zframe_size(frame)
dataPtr := C.zframe_data(frame)
b := C.GoBytes(unsafe.Pointer(dataPtr), C.int(dataSize))
more := C.zframe_more(frame)
C.zframe_destroy(&frame)
return b, int(more), nil
}
// RecvFrameNoWait receives a frame from the socket
// and returns it as a byte array if one is waiting.
// Returns an empty frame, a 0 more flag and an error
// if one is not immediately available
func (s *Sock) RecvFrameNoWait() ([]byte, int, error) {
if !s.Pollin() {
return []byte{0}, 0, ErrRecvFrame
}
return s.RecvFrame()
}
// SendMessage accepts an array of byte arrays and
// sends it as a multi-part message.
func (s *Sock) SendMessage(parts [][]byte) error {
var f int
numParts := len(parts)
for i, val := range parts {
if i == numParts-1 {
f = 0
} else {
f = FlagMore
}
err := s.SendFrame(val, f)
if err != nil {
return err
}
}
return nil
}
// RecvMessage receives a full message from the socket
// and returns it as an array of byte arrays.
func (s *Sock) RecvMessage() ([][]byte, error) {
var msg [][]byte
for {
frame, flag, err := s.RecvFrame()
if err != nil {
return msg, err
}
msg = append(msg, frame)
if flag != FlagMore {
break
}
}
return msg, nil
}
// Read provides an io.Reader interface to a zeromq socket
// DEPRECATED: see goczmq.ReadWriter
func (s *Sock) Read(p []byte) (int, error) {
var totalRead int
var totalFrame int
frame, flag, err := s.RecvFrame()
if err != nil {
return totalRead, err
}
if s.GetType() == Router {
s.clientIDs = append(s.clientIDs, string(frame))
} else {
totalRead += copy(p[:], frame[:])
totalFrame += len(frame)
}
for flag == FlagMore {
frame, flag, err = s.RecvFrame()
if err != nil {
return totalRead, err
}
totalRead += copy(p[totalRead:], frame[:])
totalFrame += len(frame)
}
if totalFrame > len(p) {
err = ErrSliceFull
} else {
err = nil
}
return totalRead, err
}
// Write provides an io.Writer interface to a zeromq socket
// DEPRECATED: See goczmq.ReadWriter
func (s *Sock) Write(p []byte) (int, error) {
var total int
if s.GetType() == Router {
err := s.SendFrame(s.GetLastClientID(), FlagMore)
if err != nil {
return total, err
}
}
err := s.SendFrame(p, 0)
if err != nil {
return total, err
}
return len(p), nil
}
// RecvMessageNoWait receives a full message from the socket
// and returns it as an array of byte arrays if one is waiting.
// Returns an empty message and an error if one is not immediately
// available
func (s *Sock) RecvMessageNoWait() ([][]byte, error) {
var msg [][]byte
if !s.Pollin() {
return msg, ErrRecvMessage
}
for {
frame, flag, err := s.RecvFrame()
if err != nil {
return msg, err
}
msg = append(msg, frame)
if flag != FlagMore {
break
}
}
return msg, nil
}
// GetType returns the socket's type
func (s *Sock) GetType() int {
return s.zType
}
// Destroy destroys the underlying zsockT.
func (s *Sock) Destroy() {
cFile := C.CString(s.file)
defer C.free(unsafe.Pointer(cFile))
C.zsock_destroy_checked(&s.zsockT, cFile, C.size_t(s.line))
}

30
vendor/gopkg.in/zeromq/goczmq.v4/sock_draft.go generated vendored Normal file
View File

@ -0,0 +1,30 @@
// +build draft
package goczmq
/*
#include "czmq.h"
*/
import "C"
const (
// Scatter is a ZMQ_SCATTER socket type
Scatter = int(C.ZMQ_SCATTER)
// Gather is a ZMQ_GATHER socket type
Gather = int(C.ZMQ_GATHER)
)
// NewGather creates a Gather socket and calls Attach.
// The socket will Bind by default.
func NewGather(endpoints string) (*Sock, error) {
s := NewSock(Gather)
return s, s.Attach(endpoints, true)
}
// NewScatter creates a Scatter socket and calls Attach.
// The socket will Connect by default.
func NewScatter(endpoints string) (*Sock, error) {
s := NewSock(Scatter)
return s, s.Attach(endpoints, false)
}

765
vendor/gopkg.in/zeromq/goczmq.v4/sock_option.go generated vendored Normal file
View File

@ -0,0 +1,765 @@
//go:generate gsl sockopts.xml
package goczmq
/* =========================================================================
zsock_option - get/set 0MQ socket options
****************************************************
* GENERATED SOURCE CODE, DO NOT EDIT!! *
* TO CHANGE THIS, EDIT sockopts.gsl *
* AND RUN gsl -q sockopts.xml *
****************************************************
Copyright (c) the Contributors as noted in the AUTHORS file.
This file is part of goczmq, the high-level go binding for CZMQ:
http://github.com/zeromq/goczmq
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
=========================================================================
*/
/*
#include "czmq.h"
#include <stdlib.h>
#include <string.h>
*/
import "C"
import (
"unsafe"
)
// SetHeartbeatIvl sets the heartbeat_ivl option for the socket
func (s *Sock) SetHeartbeatIvl(val int) {
C.zsock_set_heartbeat_ivl(unsafe.Pointer(s.zsockT), C.int(val))
}
// HeartbeatIvl returns the current value of the socket's heartbeat_ivl option
func (s *Sock) HeartbeatIvl() int {
val := C.zsock_heartbeat_ivl(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetHeartbeatTtl sets the heartbeat_ttl option for the socket
func (s *Sock) SetHeartbeatTtl(val int) {
C.zsock_set_heartbeat_ttl(unsafe.Pointer(s.zsockT), C.int(val))
}
// HeartbeatTtl returns the current value of the socket's heartbeat_ttl option
func (s *Sock) HeartbeatTtl() int {
val := C.zsock_heartbeat_ttl(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetHeartbeatTimeout sets the heartbeat_timeout option for the socket
func (s *Sock) SetHeartbeatTimeout(val int) {
C.zsock_set_heartbeat_timeout(unsafe.Pointer(s.zsockT), C.int(val))
}
// HeartbeatTimeout returns the current value of the socket's heartbeat_timeout option
func (s *Sock) HeartbeatTimeout() int {
val := C.zsock_heartbeat_timeout(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetUseFd sets the use_fd option for the socket
func (s *Sock) SetUseFd(val int) {
C.zsock_set_use_fd(unsafe.Pointer(s.zsockT), C.int(val))
}
// UseFd returns the current value of the socket's use_fd option
func (s *Sock) UseFd() int {
val := C.zsock_use_fd(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetXPubManual sets the xpub_manual option for the socket
func (s *Sock) SetXPubManual(val int) {
C.zsock_set_xpub_manual(unsafe.Pointer(s.zsockT), C.int(val))
}
// SetXPubWelcomeMsg sets the xpub_welcome_msg option for the socket
func (s *Sock) SetXPubWelcomeMsg(val string) {
cVal := C.CString(val)
defer C.free(unsafe.Pointer(cVal))
C.zsock_set_xpub_welcome_msg(unsafe.Pointer(s.zsockT), cVal)
}
// SetStreamNotify sets the stream_notify option for the socket
func (s *Sock) SetStreamNotify(val int) {
C.zsock_set_stream_notify(unsafe.Pointer(s.zsockT), C.int(val))
}
// SetInvertMatching sets the invert_matching option for the socket
func (s *Sock) SetInvertMatching(val int) {
C.zsock_set_invert_matching(unsafe.Pointer(s.zsockT), C.int(val))
}
// InvertMatching returns the current value of the socket's invert_matching option
func (s *Sock) InvertMatching() int {
val := C.zsock_invert_matching(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetXPubVerboser sets the xpub_verboser option for the socket
func (s *Sock) SetXPubVerboser(val int) {
C.zsock_set_xpub_verboser(unsafe.Pointer(s.zsockT), C.int(val))
}
// SetConnectTimeout sets the connect_timeout option for the socket
func (s *Sock) SetConnectTimeout(val int) {
C.zsock_set_connect_timeout(unsafe.Pointer(s.zsockT), C.int(val))
}
// ConnectTimeout returns the current value of the socket's connect_timeout option
func (s *Sock) ConnectTimeout() int {
val := C.zsock_connect_timeout(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetTcpMaxrt sets the tcp_maxrt option for the socket
func (s *Sock) SetTcpMaxrt(val int) {
C.zsock_set_tcp_maxrt(unsafe.Pointer(s.zsockT), C.int(val))
}
// TcpMaxrt returns the current value of the socket's tcp_maxrt option
func (s *Sock) TcpMaxrt() int {
val := C.zsock_tcp_maxrt(unsafe.Pointer(s.zsockT))
return int(val)
}
// ThreadSafe returns the current value of the socket's thread_safe option
func (s *Sock) ThreadSafe() int {
val := C.zsock_thread_safe(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetMulticastMaxtpdu sets the multicast_maxtpdu option for the socket
func (s *Sock) SetMulticastMaxtpdu(val int) {
C.zsock_set_multicast_maxtpdu(unsafe.Pointer(s.zsockT), C.int(val))
}
// MulticastMaxtpdu returns the current value of the socket's multicast_maxtpdu option
func (s *Sock) MulticastMaxtpdu() int {
val := C.zsock_multicast_maxtpdu(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetVmciBufferSize sets the vmci_buffer_size option for the socket
func (s *Sock) SetVmciBufferSize(val int) {
C.zsock_set_vmci_buffer_size(unsafe.Pointer(s.zsockT), C.int(val))
}
// VmciBufferSize returns the current value of the socket's vmci_buffer_size option
func (s *Sock) VmciBufferSize() int {
val := C.zsock_vmci_buffer_size(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetVmciBufferMinSize sets the vmci_buffer_min_size option for the socket
func (s *Sock) SetVmciBufferMinSize(val int) {
C.zsock_set_vmci_buffer_min_size(unsafe.Pointer(s.zsockT), C.int(val))
}
// VmciBufferMinSize returns the current value of the socket's vmci_buffer_min_size option
func (s *Sock) VmciBufferMinSize() int {
val := C.zsock_vmci_buffer_min_size(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetVmciBufferMaxSize sets the vmci_buffer_max_size option for the socket
func (s *Sock) SetVmciBufferMaxSize(val int) {
C.zsock_set_vmci_buffer_max_size(unsafe.Pointer(s.zsockT), C.int(val))
}
// VmciBufferMaxSize returns the current value of the socket's vmci_buffer_max_size option
func (s *Sock) VmciBufferMaxSize() int {
val := C.zsock_vmci_buffer_max_size(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetVmciConnectTimeout sets the vmci_connect_timeout option for the socket
func (s *Sock) SetVmciConnectTimeout(val int) {
C.zsock_set_vmci_connect_timeout(unsafe.Pointer(s.zsockT), C.int(val))
}
// VmciConnectTimeout returns the current value of the socket's vmci_connect_timeout option
func (s *Sock) VmciConnectTimeout() int {
val := C.zsock_vmci_connect_timeout(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetTos sets the tos option for the socket
func (s *Sock) SetTos(val int) {
C.zsock_set_tos(unsafe.Pointer(s.zsockT), C.int(val))
}
// Tos returns the current value of the socket's tos option
func (s *Sock) Tos() int {
val := C.zsock_tos(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetRouterHandover sets the router_handover option for the socket
func (s *Sock) SetRouterHandover(val int) {
C.zsock_set_router_handover(unsafe.Pointer(s.zsockT), C.int(val))
}
// SetConnectRid sets the connect_rid option for the socket
func (s *Sock) SetConnectRid(val string) {
cVal := C.CString(val)
defer C.free(unsafe.Pointer(cVal))
C.zsock_set_connect_rid(unsafe.Pointer(s.zsockT), cVal)
}
// SetHandshakeIvl sets the handshake_ivl option for the socket
func (s *Sock) SetHandshakeIvl(val int) {
C.zsock_set_handshake_ivl(unsafe.Pointer(s.zsockT), C.int(val))
}
// HandshakeIvl returns the current value of the socket's handshake_ivl option
func (s *Sock) HandshakeIvl() int {
val := C.zsock_handshake_ivl(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetSocksProxy sets the socks_proxy option for the socket
func (s *Sock) SetSocksProxy(val string) {
cVal := C.CString(val)
defer C.free(unsafe.Pointer(cVal))
C.zsock_set_socks_proxy(unsafe.Pointer(s.zsockT), cVal)
}
// SocksProxy returns the current value of the socket's socks_proxy option
func (s *Sock) SocksProxy() string {
val := C.zsock_socks_proxy(unsafe.Pointer(s.zsockT))
return C.GoString(val)
}
// SetXPubNodrop sets the xpub_nodrop option for the socket
func (s *Sock) SetXPubNodrop(val int) {
C.zsock_set_xpub_nodrop(unsafe.Pointer(s.zsockT), C.int(val))
}
// SetRouterMandatory sets the router_mandatory option for the socket
func (s *Sock) SetRouterMandatory(val int) {
C.zsock_set_router_mandatory(unsafe.Pointer(s.zsockT), C.int(val))
}
// SetProbeRouter sets the probe_router option for the socket
func (s *Sock) SetProbeRouter(val int) {
C.zsock_set_probe_router(unsafe.Pointer(s.zsockT), C.int(val))
}
// SetReqRelaxed sets the req_relaxed option for the socket
func (s *Sock) SetReqRelaxed(val int) {
C.zsock_set_req_relaxed(unsafe.Pointer(s.zsockT), C.int(val))
}
// SetReqCorrelate sets the req_correlate option for the socket
func (s *Sock) SetReqCorrelate(val int) {
C.zsock_set_req_correlate(unsafe.Pointer(s.zsockT), C.int(val))
}
// SetConflate sets the conflate option for the socket
func (s *Sock) SetConflate(val int) {
C.zsock_set_conflate(unsafe.Pointer(s.zsockT), C.int(val))
}
// SetZapDomain sets the zap_domain option for the socket
func (s *Sock) SetZapDomain(val string) {
cVal := C.CString(val)
defer C.free(unsafe.Pointer(cVal))
C.zsock_set_zap_domain(unsafe.Pointer(s.zsockT), cVal)
}
// ZapDomain returns the current value of the socket's zap_domain option
func (s *Sock) ZapDomain() string {
val := C.zsock_zap_domain(unsafe.Pointer(s.zsockT))
return C.GoString(val)
}
// Mechanism returns the current value of the socket's mechanism option
func (s *Sock) Mechanism() int {
val := C.zsock_mechanism(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetPlainServer sets the plain_server option for the socket
func (s *Sock) SetPlainServer(val int) {
C.zsock_set_plain_server(unsafe.Pointer(s.zsockT), C.int(val))
}
// PlainServer returns the current value of the socket's plain_server option
func (s *Sock) PlainServer() int {
val := C.zsock_plain_server(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetPlainUsername sets the plain_username option for the socket
func (s *Sock) SetPlainUsername(val string) {
cVal := C.CString(val)
defer C.free(unsafe.Pointer(cVal))
C.zsock_set_plain_username(unsafe.Pointer(s.zsockT), cVal)
}
// PlainUsername returns the current value of the socket's plain_username option
func (s *Sock) PlainUsername() string {
val := C.zsock_plain_username(unsafe.Pointer(s.zsockT))
return C.GoString(val)
}
// SetPlainPassword sets the plain_password option for the socket
func (s *Sock) SetPlainPassword(val string) {
cVal := C.CString(val)
defer C.free(unsafe.Pointer(cVal))
C.zsock_set_plain_password(unsafe.Pointer(s.zsockT), cVal)
}
// PlainPassword returns the current value of the socket's plain_password option
func (s *Sock) PlainPassword() string {
val := C.zsock_plain_password(unsafe.Pointer(s.zsockT))
return C.GoString(val)
}
// SetCurveServer sets the curve_server option for the socket
func (s *Sock) SetCurveServer(val int) {
C.zsock_set_curve_server(unsafe.Pointer(s.zsockT), C.int(val))
}
// CurveServer returns the current value of the socket's curve_server option
func (s *Sock) CurveServer() int {
val := C.zsock_curve_server(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetCurvePublickey sets the curve_publickey option for the socket
func (s *Sock) SetCurvePublickey(val string) {
cVal := C.CString(val)
defer C.free(unsafe.Pointer(cVal))
C.zsock_set_curve_publickey(unsafe.Pointer(s.zsockT), cVal)
}
// CurvePublickey returns the current value of the socket's curve_publickey option
func (s *Sock) CurvePublickey() string {
val := C.zsock_curve_publickey(unsafe.Pointer(s.zsockT))
return C.GoString(val)
}
// SetCurveSecretkey sets the curve_secretkey option for the socket
func (s *Sock) SetCurveSecretkey(val string) {
cVal := C.CString(val)
defer C.free(unsafe.Pointer(cVal))
C.zsock_set_curve_secretkey(unsafe.Pointer(s.zsockT), cVal)
}
// CurveSecretkey returns the current value of the socket's curve_secretkey option
func (s *Sock) CurveSecretkey() string {
val := C.zsock_curve_secretkey(unsafe.Pointer(s.zsockT))
return C.GoString(val)
}
// SetCurveServerkey sets the curve_serverkey option for the socket
func (s *Sock) SetCurveServerkey(val string) {
cVal := C.CString(val)
defer C.free(unsafe.Pointer(cVal))
C.zsock_set_curve_serverkey(unsafe.Pointer(s.zsockT), cVal)
}
// CurveServerkey returns the current value of the socket's curve_serverkey option
func (s *Sock) CurveServerkey() string {
val := C.zsock_curve_serverkey(unsafe.Pointer(s.zsockT))
return C.GoString(val)
}
// SetGssapiServer sets the gssapi_server option for the socket
func (s *Sock) SetGssapiServer(val int) {
C.zsock_set_gssapi_server(unsafe.Pointer(s.zsockT), C.int(val))
}
// GssapiServer returns the current value of the socket's gssapi_server option
func (s *Sock) GssapiServer() int {
val := C.zsock_gssapi_server(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetGssapiPlaintext sets the gssapi_plaintext option for the socket
func (s *Sock) SetGssapiPlaintext(val int) {
C.zsock_set_gssapi_plaintext(unsafe.Pointer(s.zsockT), C.int(val))
}
// GssapiPlaintext returns the current value of the socket's gssapi_plaintext option
func (s *Sock) GssapiPlaintext() int {
val := C.zsock_gssapi_plaintext(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetGssapiPrincipal sets the gssapi_principal option for the socket
func (s *Sock) SetGssapiPrincipal(val string) {
cVal := C.CString(val)
defer C.free(unsafe.Pointer(cVal))
C.zsock_set_gssapi_principal(unsafe.Pointer(s.zsockT), cVal)
}
// GssapiPrincipal returns the current value of the socket's gssapi_principal option
func (s *Sock) GssapiPrincipal() string {
val := C.zsock_gssapi_principal(unsafe.Pointer(s.zsockT))
return C.GoString(val)
}
// SetGssapiServicePrincipal sets the gssapi_service_principal option for the socket
func (s *Sock) SetGssapiServicePrincipal(val string) {
cVal := C.CString(val)
defer C.free(unsafe.Pointer(cVal))
C.zsock_set_gssapi_service_principal(unsafe.Pointer(s.zsockT), cVal)
}
// GssapiServicePrincipal returns the current value of the socket's gssapi_service_principal option
func (s *Sock) GssapiServicePrincipal() string {
val := C.zsock_gssapi_service_principal(unsafe.Pointer(s.zsockT))
return C.GoString(val)
}
// SetIpv6 sets the ipv6 option for the socket
func (s *Sock) SetIpv6(val int) {
C.zsock_set_ipv6(unsafe.Pointer(s.zsockT), C.int(val))
}
// Ipv6 returns the current value of the socket's ipv6 option
func (s *Sock) Ipv6() int {
val := C.zsock_ipv6(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetImmediate sets the immediate option for the socket
func (s *Sock) SetImmediate(val int) {
C.zsock_set_immediate(unsafe.Pointer(s.zsockT), C.int(val))
}
// Immediate returns the current value of the socket's immediate option
func (s *Sock) Immediate() int {
val := C.zsock_immediate(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetRouterRaw sets the router_raw option for the socket
func (s *Sock) SetRouterRaw(val int) {
C.zsock_set_router_raw(unsafe.Pointer(s.zsockT), C.int(val))
}
// SetIpv4only sets the ipv4only option for the socket
func (s *Sock) SetIpv4only(val int) {
C.zsock_set_ipv4only(unsafe.Pointer(s.zsockT), C.int(val))
}
// Ipv4only returns the current value of the socket's ipv4only option
func (s *Sock) Ipv4only() int {
val := C.zsock_ipv4only(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetDelayAttachOnConnect sets the delay_attach_on_connect option for the socket
func (s *Sock) SetDelayAttachOnConnect(val int) {
C.zsock_set_delay_attach_on_connect(unsafe.Pointer(s.zsockT), C.int(val))
}
// Type returns the current value of the socket's type option
func (s *Sock) Type() int {
val := C.zsock_type(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetSndhwm sets the sndhwm option for the socket
func (s *Sock) SetSndhwm(val int) {
C.zsock_set_sndhwm(unsafe.Pointer(s.zsockT), C.int(val))
}
// Sndhwm returns the current value of the socket's sndhwm option
func (s *Sock) Sndhwm() int {
val := C.zsock_sndhwm(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetRcvhwm sets the rcvhwm option for the socket
func (s *Sock) SetRcvhwm(val int) {
C.zsock_set_rcvhwm(unsafe.Pointer(s.zsockT), C.int(val))
}
// Rcvhwm returns the current value of the socket's rcvhwm option
func (s *Sock) Rcvhwm() int {
val := C.zsock_rcvhwm(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetAffinity sets the affinity option for the socket
func (s *Sock) SetAffinity(val int) {
C.zsock_set_affinity(unsafe.Pointer(s.zsockT), C.int(val))
}
// Affinity returns the current value of the socket's affinity option
func (s *Sock) Affinity() int {
val := C.zsock_affinity(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetSubscribe sets the subscribe option for the socket
func (s *Sock) SetSubscribe(val string) {
cVal := C.CString(val)
defer C.free(unsafe.Pointer(cVal))
C.zsock_set_subscribe(unsafe.Pointer(s.zsockT), cVal)
}
// SetUnsubscribe sets the unsubscribe option for the socket
func (s *Sock) SetUnsubscribe(val string) {
cVal := C.CString(val)
defer C.free(unsafe.Pointer(cVal))
C.zsock_set_unsubscribe(unsafe.Pointer(s.zsockT), cVal)
}
// SetIdentity sets the identity option for the socket
func (s *Sock) SetIdentity(val string) {
cVal := C.CString(val)
defer C.free(unsafe.Pointer(cVal))
C.zsock_set_identity(unsafe.Pointer(s.zsockT), cVal)
}
// Identity returns the current value of the socket's identity option
func (s *Sock) Identity() string {
val := C.zsock_identity(unsafe.Pointer(s.zsockT))
return C.GoString(val)
}
// SetRate sets the rate option for the socket
func (s *Sock) SetRate(val int) {
C.zsock_set_rate(unsafe.Pointer(s.zsockT), C.int(val))
}
// Rate returns the current value of the socket's rate option
func (s *Sock) Rate() int {
val := C.zsock_rate(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetRecoveryIvl sets the recovery_ivl option for the socket
func (s *Sock) SetRecoveryIvl(val int) {
C.zsock_set_recovery_ivl(unsafe.Pointer(s.zsockT), C.int(val))
}
// RecoveryIvl returns the current value of the socket's recovery_ivl option
func (s *Sock) RecoveryIvl() int {
val := C.zsock_recovery_ivl(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetSndbuf sets the sndbuf option for the socket
func (s *Sock) SetSndbuf(val int) {
C.zsock_set_sndbuf(unsafe.Pointer(s.zsockT), C.int(val))
}
// Sndbuf returns the current value of the socket's sndbuf option
func (s *Sock) Sndbuf() int {
val := C.zsock_sndbuf(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetRcvbuf sets the rcvbuf option for the socket
func (s *Sock) SetRcvbuf(val int) {
C.zsock_set_rcvbuf(unsafe.Pointer(s.zsockT), C.int(val))
}
// Rcvbuf returns the current value of the socket's rcvbuf option
func (s *Sock) Rcvbuf() int {
val := C.zsock_rcvbuf(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetLinger sets the linger option for the socket
func (s *Sock) SetLinger(val int) {
C.zsock_set_linger(unsafe.Pointer(s.zsockT), C.int(val))
}
// Linger returns the current value of the socket's linger option
func (s *Sock) Linger() int {
val := C.zsock_linger(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetReconnectIvl sets the reconnect_ivl option for the socket
func (s *Sock) SetReconnectIvl(val int) {
C.zsock_set_reconnect_ivl(unsafe.Pointer(s.zsockT), C.int(val))
}
// ReconnectIvl returns the current value of the socket's reconnect_ivl option
func (s *Sock) ReconnectIvl() int {
val := C.zsock_reconnect_ivl(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetReconnectIvlMax sets the reconnect_ivl_max option for the socket
func (s *Sock) SetReconnectIvlMax(val int) {
C.zsock_set_reconnect_ivl_max(unsafe.Pointer(s.zsockT), C.int(val))
}
// ReconnectIvlMax returns the current value of the socket's reconnect_ivl_max option
func (s *Sock) ReconnectIvlMax() int {
val := C.zsock_reconnect_ivl_max(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetBacklog sets the backlog option for the socket
func (s *Sock) SetBacklog(val int) {
C.zsock_set_backlog(unsafe.Pointer(s.zsockT), C.int(val))
}
// Backlog returns the current value of the socket's backlog option
func (s *Sock) Backlog() int {
val := C.zsock_backlog(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetMaxmsgsize sets the maxmsgsize option for the socket
func (s *Sock) SetMaxmsgsize(val int) {
C.zsock_set_maxmsgsize(unsafe.Pointer(s.zsockT), C.int(val))
}
// Maxmsgsize returns the current value of the socket's maxmsgsize option
func (s *Sock) Maxmsgsize() int {
val := C.zsock_maxmsgsize(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetMulticastHops sets the multicast_hops option for the socket
func (s *Sock) SetMulticastHops(val int) {
C.zsock_set_multicast_hops(unsafe.Pointer(s.zsockT), C.int(val))
}
// MulticastHops returns the current value of the socket's multicast_hops option
func (s *Sock) MulticastHops() int {
val := C.zsock_multicast_hops(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetRcvtimeo sets the rcvtimeo option for the socket
func (s *Sock) SetRcvtimeo(val int) {
C.zsock_set_rcvtimeo(unsafe.Pointer(s.zsockT), C.int(val))
}
// Rcvtimeo returns the current value of the socket's rcvtimeo option
func (s *Sock) Rcvtimeo() int {
val := C.zsock_rcvtimeo(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetSndtimeo sets the sndtimeo option for the socket
func (s *Sock) SetSndtimeo(val int) {
C.zsock_set_sndtimeo(unsafe.Pointer(s.zsockT), C.int(val))
}
// Sndtimeo returns the current value of the socket's sndtimeo option
func (s *Sock) Sndtimeo() int {
val := C.zsock_sndtimeo(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetXPubVerbose sets the xpub_verbose option for the socket
func (s *Sock) SetXPubVerbose(val int) {
C.zsock_set_xpub_verbose(unsafe.Pointer(s.zsockT), C.int(val))
}
// SetTcpKeepalive sets the tcp_keepalive option for the socket
func (s *Sock) SetTcpKeepalive(val int) {
C.zsock_set_tcp_keepalive(unsafe.Pointer(s.zsockT), C.int(val))
}
// TcpKeepalive returns the current value of the socket's tcp_keepalive option
func (s *Sock) TcpKeepalive() int {
val := C.zsock_tcp_keepalive(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetTcpKeepaliveIdle sets the tcp_keepalive_idle option for the socket
func (s *Sock) SetTcpKeepaliveIdle(val int) {
C.zsock_set_tcp_keepalive_idle(unsafe.Pointer(s.zsockT), C.int(val))
}
// TcpKeepaliveIdle returns the current value of the socket's tcp_keepalive_idle option
func (s *Sock) TcpKeepaliveIdle() int {
val := C.zsock_tcp_keepalive_idle(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetTcpKeepaliveCnt sets the tcp_keepalive_cnt option for the socket
func (s *Sock) SetTcpKeepaliveCnt(val int) {
C.zsock_set_tcp_keepalive_cnt(unsafe.Pointer(s.zsockT), C.int(val))
}
// TcpKeepaliveCnt returns the current value of the socket's tcp_keepalive_cnt option
func (s *Sock) TcpKeepaliveCnt() int {
val := C.zsock_tcp_keepalive_cnt(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetTcpKeepaliveIntvl sets the tcp_keepalive_intvl option for the socket
func (s *Sock) SetTcpKeepaliveIntvl(val int) {
C.zsock_set_tcp_keepalive_intvl(unsafe.Pointer(s.zsockT), C.int(val))
}
// TcpKeepaliveIntvl returns the current value of the socket's tcp_keepalive_intvl option
func (s *Sock) TcpKeepaliveIntvl() int {
val := C.zsock_tcp_keepalive_intvl(unsafe.Pointer(s.zsockT))
return int(val)
}
// SetTcpAcceptFilter sets the tcp_accept_filter option for the socket
func (s *Sock) SetTcpAcceptFilter(val string) {
cVal := C.CString(val)
defer C.free(unsafe.Pointer(cVal))
C.zsock_set_tcp_accept_filter(unsafe.Pointer(s.zsockT), cVal)
}
// TcpAcceptFilter returns the current value of the socket's tcp_accept_filter option
func (s *Sock) TcpAcceptFilter() string {
val := C.zsock_tcp_accept_filter(unsafe.Pointer(s.zsockT))
return C.GoString(val)
}
// Rcvmore returns the current value of the socket's rcvmore option
func (s *Sock) Rcvmore() int {
val := C.zsock_rcvmore(unsafe.Pointer(s.zsockT))
return int(val)
}
// Fd returns the current value of the socket's fd option
func (s *Sock) Fd() int {
val := C.zsock_fd(unsafe.Pointer(s.zsockT))
return int(val)
}
// Events returns the current value of the socket's events option
func (s *Sock) Events() int {
val := C.zsock_events(unsafe.Pointer(s.zsockT))
return int(val)
}
// LastEndpoint returns the current value of the socket's last_endpoint option
func (s *Sock) LastEndpoint() string {
val := C.zsock_last_endpoint(unsafe.Pointer(s.zsockT))
return C.GoString(val)
}

84
vendor/gopkg.in/zeromq/goczmq.v4/sock_option.gsl generated vendored Normal file
View File

@ -0,0 +1,84 @@
.# This is a code generator built using the iMatix GSL code generation
.# language. See https://github.com/imatix/gsl for details. This script
.# is licensed under MIT/X11.
.#
.output "./sock_option.go"
//go:generate gsl sockopts.xml
package goczmq
/* =========================================================================
zsock_option - get/set 0MQ socket options
****************************************************
* GENERATED SOURCE CODE, DO NOT EDIT!! *
* TO CHANGE THIS, EDIT sockopts.gsl *
* AND RUN gsl -q sockopts.xml *
****************************************************
Copyright (c) the Contributors as noted in the AUTHORS file.
This file is part of goczmq, the high-level go binding for CZMQ:
http://github.com/zeromq/goczmq
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
=========================================================================
*/
/*
#include "czmq.h"
#include <stdlib.h>
#include <string.h>
*/
import "C"
import (
"unsafe"
)
.for version
.if major = "4"
.for option
.if mode = "rw" | mode = "w"
.if type = "uint64" | type = "int64" | type = "uint32" | type = "int"
// Set$(name:pascal) sets the $(name) option for the socket
func (s *Sock) Set$(name:pascal)(val $(gotype)) {
C.zsock_set_$(name)(unsafe.Pointer(s.zsockT), C.int(val))
}
.endif
.if type = "string" | type = "key"
// Set$(name:pascal) sets the $(name) option for the socket
func (s *Sock) Set$(name:pascal)(val $(gotype)) {
cVal := C.CString(val)
defer C.free(unsafe.Pointer(cVal))
C.zsock_set_$(name)(unsafe.Pointer(s.zsockT), cVal)
}
.endif
.endif
.if mode = "rw" | mode = "r"
.if type = "uint64" | type = "int64" | type = "uint32" | type = "int"
// $(name:pascal) returns the current value of the socket's $(name) option
func (s *Sock) $(name:pascal)() $(gotype) {
val := C.zsock_$(name)(unsafe.Pointer(s.zsockT))
return int(val)
}
.endif
.if type = "string" | type = "key"
// $(name:pascal) returns the current value of the socket's $(name) option
func (s *Sock) $(name:pascal)() $(gotype) {
val := C.zsock_$(name)(unsafe.Pointer(s.zsockT))
return C.GoString(val)
}
.endif
.endif
.endfor
.endif
.for source
$(string.trim(.):)
.endfor
.endfor

83
vendor/gopkg.in/zeromq/goczmq.v4/sock_option_test.gsl generated vendored Normal file
View File

@ -0,0 +1,83 @@
.# This is a code generator built using the iMatix GSL code generation
.# language. See https://github.com/imatix/gsl for details. This script
.# is licensed under MIT/X11.
.#
.output "./sock_option_test.go"
//go:generate gsl sockopts.xml
package goczmq
/* =========================================================================
zsock_option - get/set 0MQ socket options
****************************************************
* GENERATED SOURCE CODE, DO NOT EDIT!! *
****************************************************
Copyright (c) the Contributors as noted in the AUTHORS file.
This file is part of goczmq, the high-level go binding for CZMQ:
http://github.com/zeromq/goczmq
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
=========================================================================
*/
import (
"testing"
)
.for version
.if major = "4"
.for option where defined(test)
.if mode = "rw" | mode = "w"
.if type = "uint64" | type = "int64" | type = "uint32" | type = "int"
func Test$(name:pascal)(t *testing.T) {
sock := NewSock($(test:neat))
testval := $(test_value?'1':)
sock.Set$(name:pascal)(testval)
.if mode = "rw"
val := sock.$(name:pascal)()
if val != testval && val != 0 {
t.Errorf("$(name:pascal) returned %d, should be %d", val, testval)
}
.endif
sock.Destroy()
}
.endif
.if type = "string" | type = "key"
func Test$(name:pascal)(t *testing.T) {
sock := NewSock($(test:neat))
testval := "$(test_value?'test':)"
sock.Set$(name:pascal)(testval)
.if mode = "rw"
val := sock.$(name:pascal)()
if val != testval && val != "" {
t.Errorf("$(name:pascal) returned %s should be %s", val, testval)
}
.endif
sock.Destroy()
}
.endif
.if mode = "r"
.if type = "uint64" | type = "int64" | type = "uint32" | type = "int"
func Test$(name:pascal)(t *testing.T) {
sock := NewSock($(test:neat))
_ = sock.$(name:pascal)()
sock.Destroy()
}
.endif
.if type = "string" | type = "key"
func Test$(name:pascal)(t *testing.T) {
sock := NewSock($(test:pascal))
_ = sock.$(name:pascal)()
sock.Destroy()
}
.endif
.endif
.endif
.endfor
.endif
.endfor

32
vendor/gopkg.in/zeromq/goczmq.v4/sockopts.gsl generated vendored Normal file
View File

@ -0,0 +1,32 @@
.# This is a code generator built using the iMatix GSL code generation
.# language. See https://github.com/imatix/gsl for details. This script
.# is licensed under MIT/X11.
.#
.template 0
for version
# Expand any macros
for include
for options.macro where name = include.name
for . as child
copy child to version
endfor
endfor
endfor
# Preprocess options
for option
if type = "uint64" | type = "int64" | type = "uint32" | type = "int"
option.ctype = "int"
option.ctype_const = "int"
option.gotype = "int"
elsif type = "string" | type = "key"
option.ctype = "char *" # Enforce C strings
option.ctype_const = "const char *"
option.gotype = "string"
else
echo "E: unknown type: $(type)"
endif
endfor
endfor
.endtemplate
.include "sock_option.gsl"
.include "sock_option_test.gsl"

233
vendor/gopkg.in/zeromq/goczmq.v4/sockopts.xml generated vendored Normal file
View File

@ -0,0 +1,233 @@
<?xml?>
<!-- Used to generate the socket options interface
Requires gsl4 from https://github.com/imatix/gsl
use 'gsl sockopts'
-->
<options script = "sockopts">
<version major = "4" minor = "2" style = "macro">
<!-- Options that are new in 4.2 -->
<option name = "heartbeat_ivl" type = "int" mode = "rw" test = "DEALER"
test_value = "2000" />
<option name = "heartbeat_ttl" type = "int" mode = "rw" test = "DEALER"
test_value = "4000" />
<option name = "heartbeat_timeout" type = "int" mode = "rw" test = "DEALER"
test_value = "6000" />
<option name = "use_fd" type = "int" mode = "rw" test = "REQ"
test_value = "3" />
<option name = "xpub_manual" type = "int" mode = "w" test = "XPUB"
test_value = "1" >
<restrict type = "XPUB" />
</option>
<option name = "xpub_welcome_msg" type = "string" mode = "w" test = "XPUB"
test_value = "welcome" >
<restrict type = "XPUB" />
</option>
<option name = "stream_notify" type = "int" mode = "w" test = "STREAM"
test_value = "1" >
<restrict type = "STREAM" />
</option>
<option name = "invert_matching" type = "int" mode = "rw" test = "XPUB"
test_value = "1" >
<restrict type = "XPUB" />
<restrict type = "PUB" />
<restrict type = "SUB" />
</option>
<option name = "xpub_verboser" type = "int" mode = "w" test = "XPUB"
test_value = "1" >
<restrict type = "XPUB" />
</option>
<option name = "connect_timeout" type = "int" mode = "rw" test = "DEALER"
test_value = "200" />
<option name = "tcp_maxrt" type = "int" mode = "rw" test = "DEALER"
test_value = "200" />
<option name = "thread_safe" type = "int" mode = "r" test = "DEALER"
test_value = "0" />
<option name = "multicast_maxtpdu" type = "int" mode = "rw" test = "DEALER"
test_value = "1400" />
<!-- We don't test these as libzmq doesn't always support VMCI -->
<option name = "vmci_buffer_size" type = "uint64" mode = "rw" />
<option name = "vmci_buffer_min_size" type = "uint64" mode = "rw" />
<option name = "vmci_buffer_max_size" type = "uint64" mode = "rw" />
<option name = "vmci_connect_timeout" type = "int" mode = "rw" />
</version>
<version major = "4" minor = "1" style = "macro">
<!-- Options that are new in 4.1 -->
<option name = "tos" type = "int" mode = "rw" test = "DEALER" />
<option name = "router_handover" type = "int" mode = "w" test = "ROUTER">
<restrict type = "ROUTER" />
</option>
<option name = "connect_rid" type = "key" mode = "w" test = "ROUTER"
test_value = "ABCD" >
<restrict type = "ROUTER" />
<restrict type = "STREAM" />
</option>
<option name = "handshake_ivl" type = "int" mode = "rw" test = "DEALER"
test_value = "200" />
<option name = "socks_proxy" type = "string" mode = "rw" test = "DEALER"
test_value = "127.0.0.1" />
<option name = "xpub_nodrop" type = "int" mode = "w" test = "XPUB"
test_value = "1" >
<restrict type = "XPUB" />
<restrict type = "PUB" />
</option>
</version>
<version major = "4" style = "macro">
<!-- Options that are new in 4.1 -->
<option name = "tos" type = "int" mode = "rw" test = "Dealer" />
<option name = "router_handover" type = "int" mode = "w" test = "Router">
<restrict type = "Router" />
</option>
<!-- Options that are new in 4.0 -->
<option name = "router_mandatory" type = "int" mode = "w" test = "Router">
<restrict type = "Router" />
</option>
<option name = "probe_router" type = "int" mode = "w" test = "Dealer">
<restrict type = "Router" />
<restrict type = "Dealer" />
<restrict type = "Req" />
</option>
<option name = "req_relaxed" type = "int" mode = "w" test = "Req">
<restrict type = "Req" />
</option>
<option name = "req_correlate" type = "int" mode = "w" test = "Req">
<restrict type = "Req" />
</option>
<option name = "conflate" type = "int" mode = "w" test = "Push">
<restrict type = "Push" />
<restrict type = "Pull" />
<restrict type = "Pub" />
<restrict type = "Sub" />
<restrict type = "Dealer" />
</option>
<!-- Security options -->
<option name = "zap_domain" type = "string" mode = "rw" test = "Sub" />
<option name = "mechanism" type = "int" mode = "r" test = "Sub" />
<option name = "plain_server" type = "int" mode = "rw" test = "Pub" />
<option name = "plain_username" type = "string" mode = "rw" test = "Sub" />
<option name = "plain_password" type = "string" mode = "rw" test = "Sub" />
<!-- We don't test these as libzmq doesn't always support CURVE security -->
<option name = "curve_server" type = "int" mode = "rw" />
<option name = "curve_publickey" type = "key" mode = "rw" />
<option name = "curve_secretkey" type = "key" mode = "rw" />
<option name = "curve_serverkey" type = "key" mode = "rw" />
<!-- We don't test these as libzmq doesn't always support GSSAPI security -->
<option name = "gssapi_server" type = "int" mode = "rw" />
<option name = "gssapi_plaintext" type = "int" mode = "rw" />
<option name = "gssapi_principal" type = "string" mode = "rw" />
<option name = "gssapi_service_principal"
type = "string" mode = "rw" />
<!-- New names for deprecated 3.x options -->
<option name = "ipv6" type = "int" mode = "rw" test = "Sub" />
<option name = "immediate" type = "int" mode = "rw" test = "Dealer" />
<!-- Deprecated 3.x options -->
<option name = "router_raw" type = "int" mode = "w" test = "Router">
<restrict type = "Router" />
</option>
<option name = "ipv4only" type = "int" mode = "rw" test = "Sub" />
<option name = "delay_attach_on_connect"
type = "int" mode = "w" test = "Pub" />
<!-- Options that are the same in 3.x -->
<include name = "3-x options" />
</version>
<version major = "3" style = "macro">
<!-- Options that are carried forward to 4.0 -->
<include name = "3-x options" />
<!-- Options that are deprecated in 4.0 -->
<option name = "router_raw" type = "int" mode = "w" test = "Router">
<restrict type = "Router" />
</option>
<option name = "ipv4only" type = "int" mode = "rw" test = "Sub" />
<option name = "delay_attach_on_connect"
type = "int" mode = "w" test = "Pub" />
</version>
<!-- Legacy version 2 -->
<version major = "2" style = "macro">
<option name = "hwm" type = "uint64" mode = "rw" test = "Sub" />
<option name = "swap" type = "int64" mode = "rw" test = "Sub" />
<option name = "affinity" type = "uint64" mode = "rw" test = "Sub" />
<option name = "identity" type = "string" mode = "rw" test = "Sub" />
<option name = "rate" type = "int64" mode = "rw" test = "Sub" />
<option name = "recovery_ivl" type = "int64" mode = "rw" test = "Sub" />
<option name = "recovery_ivl_msec" type = "int64" mode = "rw" test = "Sub" />
<option name = "mcast_loop" type = "int64" mode = "rw" test = "Sub" />
<option name = "rcvtimeo" type = "int" mode = "rw" test = "Sub" minor = "2" />
<option name = "sndtimeo" type = "int" mode = "rw" test = "Sub" minor = "2" />
<option name = "sndbuf" type = "uint64" mode = "rw" test = "Sub" />
<option name = "rcvbuf" type = "uint64" mode = "rw" test = "Sub" />
<option name = "linger" type = "int" mode = "rw" test = "Sub" />
<option name = "reconnect_ivl" type = "int" mode = "rw" test = "Sub" />
<option name = "reconnect_ivl_max" type = "int" mode = "rw" test = "Sub" />
<option name = "backlog" type = "int" mode = "rw" test = "Sub" />
<option name = "subscribe" type = "string" mode = "w" test = "Sub">
<restrict type = "Sub" />
</option>
<option name = "unsubscribe" type = "string" mode = "w" test = "Sub">
<restrict type = "Sub" />
</option>
<option name = "type" type = "int" mode = "r" test = "Sub" />
<option name = "rcvmore" type = "int64" mode = "r" test = "Sub" />
<option name = "fd" type = "int" mode = "r" test = "Sub" />
<option name = "events" type = "uint32" mode = "r" test = "Sub" />
</version>
<macro name = "3-x options">
<option name = "type" type = "int" mode = "r" test = "Sub" />
<option name = "sndhwm" type = "int" mode = "rw" test = "Pub" />
<option name = "rcvhwm" type = "int" mode = "rw" test = "Sub" />
<option name = "affinity" type = "uint64" mode = "rw" test = "Sub" />
<option name = "subscribe" type = "string" mode = "w" test = "Sub">
<restrict type = "Sub" />
</option>
<option name = "unsubscribe" type = "string" mode = "w" test = "Sub">
<restrict type = "Sub" />
</option>
<option name = "identity" type = "string" mode = "rw" test = "Dealer">
<restrict type = "Req" />
<restrict type = "Rep" />
<restrict type = "Dealer" />
<restrict type = "Router" />
</option>
<option name = "rate" type = "int" mode = "rw" test = "Sub" />
<option name = "recovery_ivl" type = "int" mode = "rw" test = "Sub" />
<option name = "sndbuf" type = "int" mode = "rw" test = "Pub" />
<option name = "rcvbuf" type = "int" mode = "rw" test = "Sub" />
<option name = "linger" type = "int" mode = "rw" test = "Sub" />
<option name = "reconnect_ivl" type = "int" mode = "rw" test = "Sub" />
<option name = "reconnect_ivl_max" type = "int" mode = "rw" test = "Sub" />
<option name = "backlog" type = "int" mode = "rw" test = "Sub" />
<option name = "maxmsgsize" type = "int64" mode = "rw" test = "Sub" />
<option name = "multicast_hops" type = "int" mode = "rw" test = "Sub" />
<option name = "rcvtimeo" type = "int" mode = "rw" test = "Sub" />
<option name = "sndtimeo" type = "int" mode = "rw" test = "Sub" />
<option name = "xpub_verbose" type = "int" mode = "w" test = "XPub">
<restrict type = "XPub" />
</option>
<option name = "tcp_keepalive" type = "int" mode = "rw" test = "Sub" />
<option name = "tcp_keepalive_idle"
type = "int" mode = "rw" test = "Sub" />
<option name = "tcp_keepalive_cnt" type = "int" mode = "rw" test = "Sub" />
<option name = "tcp_keepalive_intvl"
type = "int" mode = "rw" test = "Sub" />
<option name = "tcp_accept_filter" type = "string" mode = "rw" test = "Sub"
test_value = "127.0.0.1" />
<option name = "rcvmore" type = "int" mode = "r" test = "Sub" />
<option name = "fd" type = "int" mode = "r" test = "Sub" />
<option name = "events" type = "int" mode = "r" test = "Sub" />
<option name = "last_endpoint" type = "string" mode = "r" test = "Sub" />
</macro>
</options>

15
vendor/modules.txt vendored
View File

@ -1,4 +1,4 @@
# github.com/goccy/go-json v0.9.4 # github.com/goccy/go-json v0.9.5
## explicit; go 1.12 ## explicit; go 1.12
github.com/goccy/go-json github.com/goccy/go-json
github.com/goccy/go-json/internal/decoder github.com/goccy/go-json/internal/decoder
@ -15,8 +15,8 @@ github.com/golang/snappy
# github.com/json-iterator/go v1.1.12 # github.com/json-iterator/go v1.1.12
## explicit; go 1.12 ## explicit; go 1.12
github.com/json-iterator/go github.com/json-iterator/go
# github.com/labstack/echo/v4 v4.6.3 # github.com/labstack/echo/v4 v4.7.0
## explicit; go 1.15 ## explicit; go 1.17
github.com/labstack/echo/v4 github.com/labstack/echo/v4
# github.com/labstack/gommon v0.3.1 # github.com/labstack/gommon v0.3.1
## explicit; go 1.12 ## explicit; go 1.12
@ -63,18 +63,18 @@ github.com/valyala/bytebufferpool
# github.com/valyala/fasttemplate v1.2.1 # github.com/valyala/fasttemplate v1.2.1
## explicit; go 1.12 ## explicit; go 1.12
github.com/valyala/fasttemplate github.com/valyala/fasttemplate
# golang.org/x/crypto v0.0.0-20220214200702-86341886e292 # golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70
## explicit; go 1.17 ## explicit; go 1.17
golang.org/x/crypto/acme golang.org/x/crypto/acme
golang.org/x/crypto/acme/autocert golang.org/x/crypto/acme/autocert
# golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd # golang.org/x/net v0.0.0-20220225172249-27dd8689420f
## explicit; go 1.17 ## explicit; go 1.17
golang.org/x/net/http/httpguts golang.org/x/net/http/httpguts
golang.org/x/net/http2 golang.org/x/net/http2
golang.org/x/net/http2/h2c golang.org/x/net/http2/h2c
golang.org/x/net/http2/hpack golang.org/x/net/http2/hpack
golang.org/x/net/idna golang.org/x/net/idna
# golang.org/x/sys v0.0.0-20220209214540-3681064d5158 # golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5
## explicit; go 1.17 ## explicit; go 1.17
golang.org/x/sys/internal/unsafeheader golang.org/x/sys/internal/unsafeheader
golang.org/x/sys/unix golang.org/x/sys/unix
@ -87,6 +87,9 @@ golang.org/x/text/unicode/norm
# gopkg.in/ini.v1 v1.66.4 # gopkg.in/ini.v1 v1.66.4
## explicit ## explicit
gopkg.in/ini.v1 gopkg.in/ini.v1
# gopkg.in/zeromq/goczmq.v4 v4.1.0
## explicit
gopkg.in/zeromq/goczmq.v4
# xorm.io/builder v0.3.9 # xorm.io/builder v0.3.9
## explicit; go 1.11 ## explicit; go 1.11
xorm.io/builder xorm.io/builder