Example #1
0
func listen(addr, cert, key string, handler diam.Handler) error {
	// Start listening for connections.
	if len(cert) > 0 && len(key) > 0 {
		log.Println("Starting secure diameter server on", addr)
		return diam.ListenAndServeTLS(addr, cert, key, handler, nil)
	}
	log.Println("Starting diameter server on", addr)
	return diam.ListenAndServe(addr, handler, nil)
}
Example #2
0
func main() {
	local := flag.String("local", ":3868", "set local addr")
	remote := flag.String("remote", "", "set remote addr")
	files := flag.String("dict", "", "comma separated list of dictionaries")
	flag.Parse()
	upstreamAddr = *remote
	log.Println("Diameter sn🔍 op agent")
	if len(*remote) == 0 {
		log.Fatal("Missing argument -remote")
	}
	if *local == *remote {
		log.Fatal("Local and remote address are the same. Duh?")
	}
	// Load dictionary files onto the default (base protocol) dict.
	if *files != "" {
		for _, f := range strings.Split(*files, ",") {
			log.Println("Loading dictionary", f)
			if err := dict.Default.LoadFile(f); err != nil {
				log.Fatal(err)
			}
		}
	}
	// Use all CPUs.
	runtime.GOMAXPROCS(runtime.NumCPU())
	// Prepare the server.
	diam.HandleFunc("ALL", func(c diam.Conn, m *diam.Message) {
		// Forward incoming messages to the upstream server.
		if b := GetBridge(c); b != nil {
			b.Server <- m
		} else {
			// Upstream server unavailable, bye.
			c.Close()
		}
	})
	// Start the server using default handler and dict.
	log.Printf("Starting server on %s", *local)
	diam.ListenAndServe(*local, nil, nil)
}
Example #3
0
func (self *DiameterAgent) ListenAndServe() error {
	return diam.ListenAndServe(self.cgrCfg.DiameterAgentCfg().Listen, self.handlers(), nil)
}