Ejemplo n.º 1
0
func (p *PeerListener) add(addr string, con *(net.Conn)) chan *message.Message {
	/* Adds a new peer sender */
	handlePanic()
	p.mu.Lock()
	defer p.mu.Unlock()
	if _, ok := p.m[addr]; ok {
		return nil
	}
	ch := make(chan *message.Message, CHAN_BUFFER_SIZE)
	cache_no := 0
	var err error
	var storage *cache.Cache
	for {
		storage, err = cache.New(addr + "_" + strconv.Itoa(cache_no))
		if err == nil {
			break
		}
		cache_no += 1
	}
	conn := &ListenerConnection{
		channel:  ch,
		conn:     con,
		is_alive: true,
		cache:    storage,
	}
	p.m[addr] = conn
	return ch
}
Ejemplo n.º 2
0
func NewBusSocket(nodeName string) (sock *BusSocket) {
	/* Creates a new bus socket */
	handlePanic()
	cached, err := cache.New(nodeName)
	if err != nil {
		panic("Error occured while creating cache for node")
	}
	sock = &BusSocket{
		listeners:     &PeerListener{m: make(map[string]*ListenerConnection)},
		senders:       &PeerSender{m: make(map[string]*DialerConnection)},
		receiver_chan: make(chan *message.Message),
		sender_chan:   make(chan *message.Message),
		is_active:     false,
		address:       "",
		cached:        cached,
	}
	go sock.updatepeers() // Call updatepeers to start listening on sender_chan
	return sock
}