func NewRtpClient(listenIP string, listenPort int) (*RtpClient, error) { localAddr, err := net.ResolveIPAddr("ip", listenIP) if err != nil { return nil, err } rtpTransport, err := rtp.NewTransportUDP(localAddr, listenPort) if err != nil { return nil, err } session := rtp.NewSession(rtpTransport, rtpTransport) err = session.StartSession() if err != nil { return nil, err } client := &RtpClient{ listenPort: listenPort, ReceiveStats: stats.NewStats("RTP received"), MissedStats: stats.NewStats("RTP missed"), CtrlStats: stats.NewStats("RTCP events"), RtpSession: session, ctrlChan: session.CreateCtrlEventChan(rtpCtrlBuffer), dataChan: session.CreateDataReceiveChan(rtpDataBuffer), stopped: golib.NewOneshotCondition(), } client.wg.Add(1) go client.handleCtrlEvents() client.wg.Add(1) go client.handleDataPackets() return client, nil }
func NewUdpProxy(listenAddr, targetAddr string) (*UdpProxy, error) { var listenUDP, targetUDP *net.UDPAddr var err error if listenUDP, err = net.ResolveUDPAddr("udp", listenAddr); err != nil { return nil, err } if targetUDP, err = net.ResolveUDPAddr("udp", targetAddr); err != nil { return nil, err } listenConn, err := net.ListenUDP("udp", listenUDP) if err != nil { return nil, err } // TODO http://play.golang.org/p/ygGFr9oLpW // for per-UDP-packet addressing in case one proxy handles multiple connections targetConn, err := net.DialUDP("udp", nil, targetUDP) if err != nil { listenConn.Close() return nil, err } return &UdpProxy{ listenConn: listenConn, listenAddr: listenUDP, targetConn: targetConn, targetAddr: targetUDP, packets: make(chan []byte, BufferedPackets), proxyClosed: golib.NewOneshotCondition(), writeErrors: make(chan error, buf_write_errors), Stats: stats.NewStats("UDP Proxy " + listenAddr), OnError: OnErrorClose, writePausedCond: sync.Cond{L: new(sync.Mutex)}, }, nil }
func NewResults() *Results { return &Results{ packets: list.New(), startTimestamp: time.Now(), stopped: golib.NewOneshotCondition(), } }
func NewClient(protocol Protocol) Client { return &client{ protocol: protocol, closed: golib.NewOneshotCondition(), timeout: DefaultTimeout, } }
func (proto *heartbeatProtocol) ServerHandlers(server *protocols.Server) protocols.ServerHandlerMap { state := &serverState{ Server: server, heartbeatRunning: golib.NewOneshotCondition(), } return protocols.ServerHandlerMap{ codeConfigureHeartbeat: state.handleConfigureHeartbeat, } }
func (sessions Sessions) StartSession(key interface{}, session Session) { base := &SessionBase{ Wg: new(sync.WaitGroup), Stopped: golib.NewOneshotCondition(), Session: session, } sessions[key] = base base.start() session.Start(base) }
func NewFaultDetectorBase(observedProtocol Protocol, server Addr) *FaultDetectorBase { return &FaultDetectorBase{ lastErr: stateUnknown, observedServer: observedServer{ observedProtocol, server, }, Closed: golib.NewOneshotCondition(), } }
func NewServer(addr_string string, protocol Protocol) (*Server, error) { server := &Server{ errors: make(chan error, ErrorChanBuffer), stopped: golib.NewOneshotCondition(), } var err error server.protocol, err = protocol.instantiateServer(server) if err != nil { return nil, err } addr, err := protocol.Transport().Resolve(addr_string) if err != nil { return nil, err } listener, err := protocol.Transport().Listen(addr, protocol) if err != nil { return nil, err } server.listener = listener return server, nil }