Example #1
0
//NewInsight returns a new ConnInsight for use
func NewInsight(src, dest Conn) *ConnInsight {
	return &ConnInsight{
		src:    src,
		dest:   dest,
		in:     flux.NewIdentityStream(),
		out:    flux.NewIdentityStream(),
		closed: flux.NewIdentityStream(),
		Meta:   make(map[string]string),
	}
}
Example #2
0
//NewSnifer returns a new basic snifter
func NewSnifer(source string, conf *SniferConfig) (sf *Snifer) {
	sf = &Snifer{
		source:  source,
		conf:    conf,
		streams: flux.NewIdentityStream(),
		active:  0,
		killed:  0,
	}

	return
}
Example #3
0
//WhenBy takes a function that recieves a packet and performs an op and sends it to the return stream if it validates it so
func (s *Snifer) WhenBy(fx SniferMod) flux.StackStreamers {
	sx := flux.NewIdentityStream()

	_ = s.streams.Stack(func(data interface{}, _ flux.Stacks) interface{} {
		pc, ok := data.(gopacket.Packet)

		log.Printf("Checking Data if gopacket.Packet? Res: %v", ok)

		if ok {
			sx.Mux(fx(pc))
		}

		return data
	}, true)

	return sx
}
Example #4
0
//MakeDirector returns a new director instance
func MakeDirector(max, hl time.Duration, hle ErrorHandler) *Director {
	d := &Director{
		errors:      make(NotifierError),
		closer:      make(Notifier),
		health:      make(Notifier),
		do:          new(sync.Once),
		init:        new(sync.Once),
		halter:      new(sync.Once),
		resumer:     nil,
		maxage:      max,
		healthCheck: hl,
		errHandler:  hle,
		connectors:  make(map[string]Closers),
		requests:    flux.NewIdentityStream(),
		waiter:      new(sync.WaitGroup),
	}

	return d
}
Example #5
0
//NewDirector returns a new director instance
func NewDirector(max, hl time.Duration, hle ErrorHandler) *DirectorFactory {
	d := &Director{
		errors:      make(NotifierError),
		closer:      make(Notifier),
		health:      make(Notifier),
		do:          new(sync.Once),
		init:        new(sync.Once),
		halter:      new(sync.Once),
		resumer:     nil,
		tcp:         TCPStream(hle),
		http:        HTTPStream(hle),
		maxage:      max,
		healthCheck: hl,
		errHandler:  hle,
		connectors:  make(map[string]Closers),
		requests:    flux.NewIdentityStream(),
		waiter:      new(sync.WaitGroup),
	}

	dd := NewFactory(d)
	// addFactoryDefaults(dd)
	return dd
}
Example #6
0
//NewController returns a new BaseController instance
func NewController(name string, profile *ControlProfile, sni *SniferConfig) (*BaseController, error) {

	if name == "" {
		panic(fmt.Sprintf("Lxcontroller.Error Container name can not be empty"))
	}

	c, err := lxc.NewContainer(name, profile.Path)

	if err != nil {
		checkError(err, fmt.Sprintf("Allocating Container %s", name))
	} else {
		checkError(err, fmt.Sprintf("Allocated Container %s", name))
	}

	if !c.Defined() {

		log.Printf("Container %s is not defined, will try and create", name)

		if profile.Create == nil {
			log.Printf("ControlProfile has no creation template options for %s", name)
			return nil, ErrBadController
		}

		log.Printf("Using profile %+v for creating container %s", profile.Create, name)

		err = c.Create(*profile.Create)

		if err != nil {
			checkError(err, fmt.Sprintf("Creating Container (%s) with call to .Create()", name))
			return nil, err
		}

	}

	c.SetVerbosity(lxc.Verbose)

	b := &BaseController{
		bname:      name,
		bip:        "",
		bcontainer: c,
		bprofile:   profile,
		sniferConf: sni,
		snifer:     NewSnifer("", sni),
		frozen:     flux.NewIdentityStream(),
		closed:     flux.NewIdentityStream(),
		unfrozen:   flux.NewIdentityStream(),
	}

	confs := b.Profile().Configurations

	confs.Each(func(v, k interface{}, _ func()) {
		ks, ok := k.(string)
		if ok {
			vs, ok := v.(string)
			if ok {
				checkError(c.SetConfigItem(ks, vs), fmt.Sprintf("Setting Container Config Key:(%s) Value:(%s)", ks, vs))
			}
		}
	})

	if b.Profile().Durations.Stop != zero {
		log.Printf("Controller %s setting up Stop Timer at duration of %+s", b.Name(), b.Profile().Durations.Stop)
		b.stopper = flux.NewResetTimer(func() {}, func() {
			b.Drop()
		}, b.Profile().Durations.Stop, false, false)
	}

	if b.Profile().Durations.Freeze != zero {
		log.Printf("Controller %s setting up Freeze Timer at duration of %+s", b.Name(), b.Profile().Durations.Freeze)
		b.ticker = flux.NewResetTimer(func() {
			log.Println("unfreezing it now!")
			b.Unfreeze()
		}, func() {
			log.Println("freezing it now!")
			b.Freeze()
		}, b.Profile().Durations.Freeze, false, false)
	}

	return b, err
}