Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused code #371

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 0 additions & 55 deletions config/delay.go

This file was deleted.

8 changes: 0 additions & 8 deletions director/director.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ func Get(key string) (func(...func(Director) error) (Director, error), bool) {
return nil, false
}

func GetAvailableDirectorNames() []string {
var out []string
for key := range directors {
out = append(out, key)
}
return out
}

// Director defines an interface which exposes an interface to allow structures that
// implement this interface allow us to control containers which they provide.
type Director interface {
Expand Down
49 changes: 0 additions & 49 deletions director/dummy.go

This file was deleted.

3 changes: 1 addition & 2 deletions pushers/eventbus/eventbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ func New() *EventBus {
}

// Subscribe adds the giving channel to the list of subscribers for the giving bus.
func (eb *EventBus) Subscribe(channel pushers.Channel) error {
func (eb *EventBus) Subscribe(channel pushers.Channel) {
eb.subscribers = append(eb.subscribers, channel)
return nil
}

// Send deliverers the slice of messages to all subscribers.
Expand Down
29 changes: 8 additions & 21 deletions server/honeytrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ type Honeytrap struct {
// TODO(nl5887): rename to bus, should we encapsulate this?
bus *eventbus.EventBus

director director.Director

token string

dataDir string
Expand All @@ -131,7 +129,6 @@ func New(options ...OptionFn) (*Honeytrap, error) {

h := &Honeytrap{
config: conf,
director: director.MustDummy(),
bus: bus,
profiler: profiler.Dummy(),
}
Expand Down Expand Up @@ -397,9 +394,7 @@ func (hc *Honeytrap) Run(ctx context.Context) {
channel = pushers.FilterChannel(channel, pushers.RegexFilterFunc("service", x.Services))
}

if err := hc.bus.Subscribe(channel); err != nil {
log.Error("Could not add channel %s to bus: %s", name, err.Error())
}
hc.bus.Subscribe(channel)
}
}

Expand All @@ -411,7 +406,6 @@ func (hc *Honeytrap) Run(ctx context.Context) {

// initialize directors
directors := map[string]director.Director{}
availableDirectorNames := director.GetAvailableDirectorNames()

for key, s := range hc.config.Directors {
x := struct {
Expand All @@ -430,7 +424,7 @@ func (hc *Honeytrap) Run(ctx context.Context) {
}

if directorFunc, ok := director.Get(x.Type); !ok {
log.Error("Director type=%s not supported on platform (director=%s). Available directors: %s", x.Type, key, strings.Join(availableDirectorNames, ", "))
log.Error("Director type=%s not supported on platform (director=%s) (use --list-directors to see available directors)", x.Type, key)
} else if d, err := directorFunc(
director.WithChannel(hc.bus),
director.WithConfig(s),
Expand All @@ -455,13 +449,8 @@ func (hc *Honeytrap) Run(ctx context.Context) {
fmt.Println(color.RedString("Listener not set"))
}

var enabledDirectorNames []string
for key := range directors {
enabledDirectorNames = append(enabledDirectorNames, key)
}

serviceList := make(map[string]*ServiceMap)
isServiceUsed := make(map[string]bool) // Used to check that every service is used by a port
serviceList := make(map[string]*ServiceMap)
// same for proxies
for key, s := range hc.config.Services {
x := struct {
Expand Down Expand Up @@ -490,13 +479,13 @@ func (hc *Honeytrap) Run(ctx context.Context) {
} else if d, ok := directors[x.Director]; ok {
options = append(options, services.WithDirector(d))
} else {
log.Error(color.RedString("Could not find director=%s for service=%s. Enabled directors: %s", x.Director, key, strings.Join(enabledDirectorNames, ", ")))
log.Error("Could not find director=%s for service=%s (use --list-directors to see available directors)", x.Director, key)
continue
}

fn, ok := services.Get(x.Type)
if !ok {
log.Error(color.RedString("Could not find type %s for service %s", x.Type, key))
log.Error("Could not find type %s for service %s", x.Type, key)
continue
}

Expand All @@ -512,8 +501,7 @@ func (hc *Honeytrap) Run(ctx context.Context) {

listenerFunc, ok := listener.Get(x.Type)
if !ok {
fmt.Println(color.RedString("Listener %s not support on platform", x.Type))
return
log.Fatalf("Listener %s not support on platform", x.Type)
}

l, err := listenerFunc(
Expand Down Expand Up @@ -617,8 +605,7 @@ func (hc *Honeytrap) Run(ctx context.Context) {
}

if err := l.Start(ctx); err != nil {
fmt.Println(color.RedString("Error starting listener: %s", err.Error()))
return
log.Fatalf("Error starting listener: %s", err.Error())
}

incoming := make(chan net.Conn)
Expand Down Expand Up @@ -720,7 +707,7 @@ func (hc *Honeytrap) handle(conn net.Conn) {

ctx := context.Background()
if err := sm.Service.Handle(ctx, newConn); err != nil {
log.Errorf(color.RedString("Error handling service: %s: %s", sm.Name, err.Error()))
log.Errorf("Error handling service: %s: %s", sm.Name, err.Error())
}
}

Expand Down