//create connection pool and tests func main() { service_id := []byte("id short") cpool1 := SpawnConnectionPool(6060) //connection pool sm1 := gnet.NewServiceManager(cpool1) //service manager //add services swd1 := NewSkywireDaemon(sm1) //server tss1 := NewTestServiceServer() sm1.AddService( service_id, []byte("id long"), 1, tss1) cpool2 := SpawnConnectionPool(6061) sm2 := gnet.NewServiceManager(cpool2) //add services swd2 := NewSkywireDaemon(sm2) //sm2.AddService([]byte("Skywire Daemon"), 0, swd2) tss2 := NewTestServiceServer() sm2.AddService( service_id, []byte("id long"), 1, tss2) //TODO: do need servive level connect function? //connect to peer con, err := cpool1.Connect("127.0.0.1:6061") _ = con if err != nil { log.Panic(err) } //connection attempt message scm := ServiceConnectMessage{} scm.LocalChannel = 1 //channel of local service scm.RemoteChannel = 1 //channel of remote service scm.Originating = 1 scm.ErrorMessage = []byte("") //send connection intiation swd1.Service.Send(con, &scm) //create a message to send //tm := TestMessage{Text: []byte("Message test")} //d1.SendMessage(con, 3, &tm) _ = swd1 _ = swd2 time.Sleep(time.Second * 10) }
// Returns a Daemon with primitives allocated func NewDaemon(config Config) *Daemon { config = config.preprocess() // c.DHT.address = c.Daemon.Address d := &Daemon{ Config: config.Daemon, Peers: NewPeers(config.Peers), ExpectingIntroductions: make(map[string]time.Time), // TODO -- if there are performance problems from blocking chans, // Its because we are connecting to more things than OutgoingMax // if we have private peers connectionErrors: make(chan ConnectionError, config.Daemon.OutgoingMax), OutgoingConnections: make(map[string]*gnet.Connection, config.Daemon.OutgoingMax), pendingConnections: make(map[string]([]*gnet.Service), config.Daemon.PendingMax), } d.Peers.Init() if config.DHT.Disabled == false { d.DHT = dht.NewDHT(config.DHT) d.DHT.Init() } //gnet set connection pool gnet_config := gnet.NewConfig() gnet_config.Port = uint16(d.Config.Port) //set listening port gnet_config.Address = d.Config.Address d.Pool = gnet.NewConnectionPool(gnet_config) //service manager d.ServiceManager = gnet.NewServiceManager(d.Pool) ds := NewDaemonService(d.ServiceManager, d) d.Service = ds.Service return d }