Declare the Dissect function in the extension API

This commit is contained in:
M. Mert Yildiran 2021-08-17 09:23:19 +03:00
parent 5ce85f4162
commit 4e4644d3ce
No known key found for this signature in database
GPG Key ID: D42ADB236521BF7A
5 changed files with 32 additions and 7 deletions

View File

@ -1,6 +1,9 @@
package api
import "plugin"
import (
"bufio"
"plugin"
)
type Extension struct {
Name string
@ -13,4 +16,5 @@ type Extension struct {
type Dissector interface {
Register(*Extension)
Ping()
Dissect(b *bufio.Reader) interface{}
}

View File

@ -1,7 +1,7 @@
package main
import (
"fmt"
"bufio"
"log"
"github.com/up9inc/mizu/tap/api"
@ -19,7 +19,12 @@ func (g dissecting) Register(extension *api.Extension) {
}
func (g dissecting) Ping() {
fmt.Printf("pong AMQP\n")
log.Printf("pong AMQP\n")
}
func (g dissecting) Dissect(b *bufio.Reader) interface{} {
// TODO: Implement
return nil
}
// exported as symbol named "Greeter"

View File

@ -1,8 +1,9 @@
package main
import (
"fmt"
"bufio"
"log"
"net/http"
"github.com/up9inc/mizu/tap/api"
)
@ -19,7 +20,14 @@ func (g dissecting) Register(extension *api.Extension) {
}
func (g dissecting) Ping() {
fmt.Printf("pong HTTP\n")
log.Printf("pong HTTP\n")
}
func (g dissecting) Dissect(b *bufio.Reader) interface{} {
log.Printf("called Dissect!")
req, _ := http.ReadRequest(b)
log.Printf("HTTP Request: %+v\n", req)
return nil
}
// exported as symbol named "Greeter"

View File

@ -1,7 +1,7 @@
package main
import (
"fmt"
"bufio"
"log"
"github.com/up9inc/mizu/tap/api"
@ -19,7 +19,12 @@ func (g dissecting) Register(extension *api.Extension) {
}
func (g dissecting) Ping() {
fmt.Printf("pong Kafka\n")
log.Printf("pong Kafka\n")
}
func (g dissecting) Dissect(b *bufio.Reader) interface{} {
// TODO: Implement
return nil
}
// exported as symbol named "Greeter"

View File

@ -1,6 +1,7 @@
package tap
import (
"bufio"
"fmt"
"io"
"sync"
@ -39,7 +40,9 @@ func (h *tcpStream) run(wg *sync.WaitGroup) {
defer wg.Done()
for _, extension := range extensions {
if containsPort(extension.Ports, h.transport.Dst().String()) {
b := bufio.NewReader(h)
extension.Dissector.Ping()
extension.Dissector.Dissect(b)
}
}
// b := bufio.NewReader(h)