ing
This commit is contained in:
commit
8d60284f54
68
.gitignore
vendored
Normal file
68
.gitignore
vendored
Normal file
|
@ -0,0 +1,68 @@
|
|||
# Created by .ignore support plugin (hsz.mobi)
|
||||
### JetBrains template
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff:
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/dictionaries
|
||||
|
||||
# Sensitive or high-churn files:
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.xml
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
|
||||
# Gradle:
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Mongo Explorer plugin:
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
## File-based project format:
|
||||
*.iws
|
||||
|
||||
## Plugin-specific files:
|
||||
|
||||
# IntelliJ
|
||||
/out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
### Go template
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, build with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
|
||||
.glide/
|
||||
.idea/
|
||||
*.iml
|
||||
|
||||
vendor/
|
||||
glide.lock
|
||||
.DS_Store
|
||||
dist/
|
||||
debug
|
32
.vscode/launch.json
vendored
Normal file
32
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Debug",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "debug",
|
||||
"remotePath": "",
|
||||
"port": 2345,
|
||||
"host": "127.0.0.1",
|
||||
"program": "${workspaceRoot}/main.go",
|
||||
"env": {},
|
||||
"args": [],
|
||||
"showLog": true
|
||||
},
|
||||
{
|
||||
"name": "File Debug",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "debug",
|
||||
"remotePath": "",
|
||||
"port": 2345,
|
||||
"host": "127.0.0.1",
|
||||
"program": "${fileDirname}",
|
||||
"env": {},
|
||||
"args": [],
|
||||
"showLog": true
|
||||
}
|
||||
|
||||
]
|
||||
}
|
4
.vscode/settings.json
vendored
Normal file
4
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
"java.configuration.updateBuildConfiguration": "automatic"
|
||||
}
|
15
client/client.go
Normal file
15
client/client.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
crc "git.loafle.net/commons_go/rpc/client"
|
||||
crcrs "git.loafle.net/commons_go/rpc/client/rwc/socket"
|
||||
csc "git.loafle.net/commons_go/server/client"
|
||||
)
|
||||
|
||||
func New(clientHandler ClientHandler, socketBuilder csc.SocketBuilder) crc.Client {
|
||||
cRWCHandler := crcrs.New(socketBuilder)
|
||||
|
||||
c := crc.New(clientHandler, cRWCHandler)
|
||||
|
||||
return c
|
||||
}
|
7
client/client_handler.go
Normal file
7
client/client_handler.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package client
|
||||
|
||||
import "git.loafle.net/commons_go/rpc/client"
|
||||
|
||||
type ClientHandler interface {
|
||||
client.ClientHandler
|
||||
}
|
19
client/client_handlers.go
Normal file
19
client/client_handlers.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
crc "git.loafle.net/commons_go/rpc/client"
|
||||
"git.loafle.net/commons_go/rpc/protocol/json"
|
||||
crr "git.loafle.net/commons_go/rpc/registry"
|
||||
)
|
||||
|
||||
func NewClientHandler(rpcInvoker crr.RPCInvoker) ClientHandler {
|
||||
ch := &ClientHandlers{}
|
||||
ch.RPCInvoker = rpcInvoker
|
||||
ch.Codec = json.NewClientCodec()
|
||||
|
||||
return ch
|
||||
}
|
||||
|
||||
type ClientHandlers struct {
|
||||
crc.ClientHandlers
|
||||
}
|
17
client/socket_builders.go
Normal file
17
client/socket_builders.go
Normal file
|
@ -0,0 +1,17 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
csc "git.loafle.net/commons_go/server/client"
|
||||
)
|
||||
|
||||
func NewSocketBuilder(address string) csc.SocketBuilder {
|
||||
return newSocketBuilder(address)
|
||||
}
|
||||
|
||||
type SocketBuilders struct {
|
||||
csc.SocketBuilders
|
||||
}
|
||||
|
||||
func (sb *SocketBuilders) SocketHandler() csc.SocketHandler {
|
||||
return NewSocketHandler()
|
||||
}
|
13
client/socket_builders_unix.go
Normal file
13
client/socket_builders_unix.go
Normal file
|
@ -0,0 +1,13 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
csc "git.loafle.net/commons_go/server/client"
|
||||
)
|
||||
|
||||
func newSocketBuilder(address string) csc.SocketBuilder {
|
||||
sb := &SocketBuilders{}
|
||||
sb.Network = "unix"
|
||||
sb.Address = address
|
||||
|
||||
return sb
|
||||
}
|
23
client/socket_builders_windows.go
Normal file
23
client/socket_builders_windows.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
csc "git.loafle.net/commons_go/server/client"
|
||||
"gopkg.in/natefinch/npipe.v2"
|
||||
)
|
||||
|
||||
func newSocketBuilder(address string) csc.SocketBuilder {
|
||||
sb := &SocketBuilders{}
|
||||
sb.Network = "pipe"
|
||||
sb.Address = address
|
||||
|
||||
return sb
|
||||
}
|
||||
|
||||
func (sb *SocketBuilders) Dial(network, address string) (net.Conn, error) {
|
||||
if 0 == sb.HandshakeTimeout {
|
||||
return npipe.Dial(`\\.\pipe\` + address)
|
||||
}
|
||||
return npipe.DialTimeout(`\\.\pipe\`+address, sb.HandshakeTimeout)
|
||||
}
|
28
client/socket_handlers.go
Normal file
28
client/socket_handlers.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net"
|
||||
|
||||
csc "git.loafle.net/commons_go/server/client"
|
||||
)
|
||||
|
||||
type SocketHandlers struct {
|
||||
csc.SocketHandlers
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) OnConnect(socketContext csc.SocketContext, conn net.Conn) {
|
||||
log.Printf("OnConnect res: %v \n", conn)
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) OnDisconnect(soc csc.Socket) {
|
||||
log.Printf("OnDisconnect \n")
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) Validate() {
|
||||
sh.SocketHandlers.Validate()
|
||||
}
|
||||
|
||||
func NewSocketHandler() csc.SocketHandler {
|
||||
return &SocketHandlers{}
|
||||
}
|
2
glide.yaml
Normal file
2
glide.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
package: git.loafle.net/overflow/overflow_probe_container_network
|
||||
import: []
|
47
main.go
Normal file
47
main.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
"git.loafle.net/overflow/overflow_probe_container_network/server"
|
||||
)
|
||||
|
||||
var (
|
||||
sockFile *string
|
||||
)
|
||||
|
||||
func init() {
|
||||
sockFile = flag.String("sock", serverAddr, "Socket file")
|
||||
flag.Parse()
|
||||
|
||||
}
|
||||
|
||||
func main() {
|
||||
defer logging.Logger().Sync()
|
||||
|
||||
s := server.New(*sockFile)
|
||||
|
||||
stop := make(chan os.Signal)
|
||||
signal.Notify(stop, syscall.SIGINT)
|
||||
|
||||
go func() {
|
||||
if err := s.Start(); nil != err {
|
||||
log.Printf("Server: Start error %v", err)
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
select {
|
||||
case signal := <-stop:
|
||||
fmt.Printf("Got signal: %v\n", signal)
|
||||
}
|
||||
|
||||
s.Stop()
|
||||
|
||||
}
|
3
main_unix.go
Normal file
3
main_unix.go
Normal file
|
@ -0,0 +1,3 @@
|
|||
package main
|
||||
|
||||
var serverAddr string = "/tmp/container_network.sock"
|
3
main_windows.go
Normal file
3
main_windows.go
Normal file
|
@ -0,0 +1,3 @@
|
|||
package main
|
||||
|
||||
var serverAddr string = "container_network"
|
9
server/rpc_servlet_handler.go
Normal file
9
server/rpc_servlet_handler.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"git.loafle.net/commons_go/rpc/server"
|
||||
)
|
||||
|
||||
type RPCServletHandler interface {
|
||||
server.ServletHandler
|
||||
}
|
22
server/rpc_servlet_handlers.go
Normal file
22
server/rpc_servlet_handlers.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
crr "git.loafle.net/commons_go/rpc/registry"
|
||||
"git.loafle.net/commons_go/rpc/server"
|
||||
)
|
||||
|
||||
func newRPCServletHandler(rpcInvoker crr.RPCInvoker) server.ServletHandler {
|
||||
sh := &RPCServletHandlers{}
|
||||
sh.RPCInvoker = rpcInvoker
|
||||
|
||||
return sh
|
||||
}
|
||||
|
||||
type RPCServletHandlers struct {
|
||||
server.ServletHandlers
|
||||
}
|
||||
|
||||
func (sh *RPCServletHandlers) Validate() {
|
||||
sh.ServletHandlers.Validate()
|
||||
|
||||
}
|
24
server/server.go
Normal file
24
server/server.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
crpj "git.loafle.net/commons_go/rpc/protocol/json"
|
||||
crr "git.loafle.net/commons_go/rpc/registry"
|
||||
"git.loafle.net/commons_go/server"
|
||||
|
||||
"git.loafle.net/overflow/overflow_probe_container_network/service"
|
||||
)
|
||||
|
||||
func New(addr string) server.Server {
|
||||
rpcRegistry := crr.NewRPCRegistry()
|
||||
service.RegisterRPC(rpcRegistry)
|
||||
|
||||
rpcSH := newRPCServletHandler(rpcRegistry)
|
||||
rpcSH.RegisterCodec(crpj.Name, crpj.NewServerCodec())
|
||||
|
||||
socketHandler := newSocketHandler(rpcSH)
|
||||
|
||||
sh := newServerHandler(addr, socketHandler)
|
||||
s := server.New(sh)
|
||||
|
||||
return s
|
||||
}
|
7
server/server_handler.go
Normal file
7
server/server_handler.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package server
|
||||
|
||||
import "git.loafle.net/commons_go/server"
|
||||
|
||||
type ServerHandler interface {
|
||||
server.ServerHandler
|
||||
}
|
52
server/server_handlers.go
Normal file
52
server/server_handlers.go
Normal file
|
@ -0,0 +1,52 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
|
||||
"git.loafle.net/commons_go/server"
|
||||
)
|
||||
|
||||
func newServerHandler(addr string, socketHandler SocketHandler) ServerHandler {
|
||||
sh := &ServerHandlers{
|
||||
addr: addr,
|
||||
}
|
||||
|
||||
sh.Name = "Network Container"
|
||||
sh.SocketHandler = socketHandler
|
||||
return sh
|
||||
}
|
||||
|
||||
type ServerHandlers struct {
|
||||
server.ServerHandlers
|
||||
|
||||
addr string
|
||||
}
|
||||
|
||||
func (sh *ServerHandlers) Init(serverCTX server.ServerContext) error {
|
||||
if err := sh.ServerHandlers.Init(serverCTX); nil != err {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sh *ServerHandlers) OnStart(serverCTX server.ServerContext) {
|
||||
sh.ServerHandlers.OnStart(serverCTX)
|
||||
|
||||
}
|
||||
|
||||
func (sh *ServerHandlers) OnStop(serverCTX server.ServerContext) {
|
||||
|
||||
sh.ServerHandlers.OnStop(serverCTX)
|
||||
}
|
||||
|
||||
func (sh *ServerHandlers) Validate() {
|
||||
sh.ServerHandlers.Validate()
|
||||
|
||||
if "" == sh.addr {
|
||||
logging.Logger().Panic(fmt.Sprintf("Server: Address of server must be specified"))
|
||||
}
|
||||
|
||||
}
|
17
server/server_handlers_unix.go
Normal file
17
server/server_handlers_unix.go
Normal file
|
@ -0,0 +1,17 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
|
||||
"git.loafle.net/commons_go/server"
|
||||
)
|
||||
|
||||
func (sh *ServerHandlers) Listen(serverCTX server.ServerContext) (net.Listener, error) {
|
||||
os.Remove(sh.addr)
|
||||
l, err := net.ListenUnix("unix", &net.UnixAddr{Name: sh.addr, Net: "unix"})
|
||||
if nil == err {
|
||||
os.Chmod(sh.addr, 0777)
|
||||
}
|
||||
return l, err
|
||||
}
|
16
server/server_handlers_windows.go
Normal file
16
server/server_handlers_windows.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"git.loafle.net/commons_go/server"
|
||||
npipe "gopkg.in/natefinch/npipe.v2"
|
||||
)
|
||||
|
||||
func (sh *ServerHandlers) Listen(serverCTX server.ServerContext) (net.Listener, error) {
|
||||
ln, err := npipe.Listen(`\\.\pipe\` + sh.addr)
|
||||
if err != nil {
|
||||
// handle error
|
||||
}
|
||||
return ln, err
|
||||
}
|
9
server/socket_handler.go
Normal file
9
server/socket_handler.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"git.loafle.net/commons_go/server"
|
||||
)
|
||||
|
||||
type SocketHandler interface {
|
||||
server.SocketHandler
|
||||
}
|
101
server/socket_handlers.go
Normal file
101
server/socket_handlers.go
Normal file
|
@ -0,0 +1,101 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
cRPC "git.loafle.net/commons_go/rpc"
|
||||
crsrs "git.loafle.net/commons_go/rpc/server/rwc/socket"
|
||||
|
||||
"git.loafle.net/commons_go/rpc/protocol/json"
|
||||
"git.loafle.net/commons_go/server"
|
||||
)
|
||||
|
||||
func newSocketHandler(rpcSH RPCServletHandler) SocketHandler {
|
||||
rpcRWCSH := crsrs.New()
|
||||
|
||||
sh := &SocketHandlers{
|
||||
rpcSH: rpcSH,
|
||||
rpcRWCSH: rpcRWCSH,
|
||||
}
|
||||
|
||||
return sh
|
||||
}
|
||||
|
||||
type SocketHandlers struct {
|
||||
server.SocketHandlers
|
||||
|
||||
rpcRWCSH cRPC.ServletReadWriteCloseHandler
|
||||
rpcSH RPCServletHandler
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) Init(serverCTX server.ServerContext) error {
|
||||
if err := sh.SocketHandlers.Init(serverCTX); nil != err {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) Handshake(socketCTX server.SocketContext, conn net.Conn) (id string) {
|
||||
return "discovery"
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) OnConnect(soc server.Socket) {
|
||||
sh.SocketHandlers.OnConnect(soc)
|
||||
|
||||
soc.Context().SetAttribute(cRPC.ContentTypeKey, json.Name)
|
||||
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) Handle(soc server.Socket, stopChan <-chan struct{}, doneChan chan<- error) {
|
||||
var err error
|
||||
rpcServlet := retainRPCServlet(sh.rpcSH, sh.rpcRWCSH)
|
||||
|
||||
defer func() {
|
||||
releaseRPCServlet(rpcServlet)
|
||||
doneChan <- err
|
||||
}()
|
||||
|
||||
rpcDoneChan := make(chan error, 1)
|
||||
|
||||
if err = rpcServlet.Start(soc.Context(), soc, rpcDoneChan); nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
select {
|
||||
case err = <-rpcDoneChan:
|
||||
case <-stopChan:
|
||||
rpcServlet.Stop()
|
||||
<-rpcDoneChan
|
||||
}
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) OnDisconnect(soc server.Socket) {
|
||||
|
||||
sh.SocketHandlers.OnDisconnect(soc)
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) Destroy() {
|
||||
|
||||
sh.SocketHandlers.Destroy()
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) Validate() {
|
||||
|
||||
}
|
||||
|
||||
var rpcServletPool sync.Pool
|
||||
|
||||
func retainRPCServlet(sh RPCServletHandler, rpcRWCSH cRPC.ServletReadWriteCloseHandler) cRPC.Servlet {
|
||||
v := rpcServletPool.Get()
|
||||
if v == nil {
|
||||
return cRPC.NewServlet(sh, rpcRWCSH)
|
||||
}
|
||||
return v.(cRPC.Servlet)
|
||||
}
|
||||
|
||||
func releaseRPCServlet(s cRPC.Servlet) {
|
||||
|
||||
rpcServletPool.Put(s)
|
||||
}
|
16
service/ConfigService.go
Normal file
16
service/ConfigService.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package service
|
||||
|
||||
type ConfigService struct {
|
||||
}
|
||||
|
||||
func (cs *ConfigService) Add() {
|
||||
|
||||
}
|
||||
|
||||
func (cs *ConfigService) Remove() {
|
||||
|
||||
}
|
||||
|
||||
func (cs *ConfigService) Init() {
|
||||
|
||||
}
|
13
service/ContainerService.go
Normal file
13
service/ContainerService.go
Normal file
|
@ -0,0 +1,13 @@
|
|||
package service
|
||||
|
||||
type ContainerService struct {
|
||||
}
|
||||
|
||||
func (cs *ContainerService) Get(crawlerName string, sensorID string) (interface{}, error) {
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (cs *ContainerService) State() {
|
||||
|
||||
}
|
9
service/service.go
Normal file
9
service/service.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
crr "git.loafle.net/commons_go/rpc/registry"
|
||||
)
|
||||
|
||||
func RegisterRPC(rpcRegistry crr.RPCRegistry) {
|
||||
rpcRegistry.RegisterService(&ContainerService{}, "")
|
||||
}
|
Loading…
Reference in New Issue
Block a user