Beispiel #1
0
// create a new connection from an established connection
func newOutboundConn(c net.Conn, s *Server, conf *config.FeedConfig) Conn {

	sname := s.Name()

	if len(sname) == 0 {
		sname = "nntp.anon.tld"
	}
	storage := s.Storage
	if storage == nil {
		storage = store.NewNullStorage()
	}
	return &v1OBConn{
		conf: conf,
		C: v1Conn{
			hooks: s,
			state: ConnState{
				FeedName: conf.Name,
				HostName: conf.Addr,
				Open:     true,
			},
			serverName: sname,
			storage:    storage,
			C:          textproto.NewConn(c),
			conn:       c,
			hdrio:      message.NewHeaderIO(),
		},
	}
}
Beispiel #2
0
func newInboundConn(s *Server, c net.Conn) Conn {
	sname := s.Name()
	storage := s.Storage
	if storage == nil {
		storage = store.NewNullStorage()
	}
	anon := false
	if s.Config != nil {
		anon = s.Config.AnonNNTP
	}
	return &v1IBConn{
		C: v1Conn{
			state: ConnState{
				FeedName: "inbound-feed",
				HostName: c.RemoteAddr().String(),
				Open:     true,
			},
			auth:          s.Auth,
			authenticated: anon,
			serverName:    sname,
			storage:       storage,
			acceptor:      s.Acceptor,
			hdrio:         message.NewHeaderIO(),
			C:             textproto.NewConn(c),
			conn:          c,
			cmds: map[string]lineHandlerFunc{
				"STARTTLS":     upgradeTLS,
				"IHAVE":        nntpRecvArticle,
				"POST":         nntpPostArticle,
				"MODE":         switchModeInbound,
				"QUIT":         quitConnection,
				"CAPABILITIES": sendCapabilities,
				"CHECK":        streamingLine,
				"TAKETHIS":     streamingLine,
				"LIST": func(c *v1Conn, line string, h EventHooks) error {
					return newsgroupList(c, line, h, RPL_List)
				},
				"NEWSGROUPS": func(c *v1Conn, line string, h EventHooks) error {
					return newsgroupList(c, line, h, RPL_NewsgroupList)
				},
				"GROUP":    switchNewsgroup,
				"AUTHINFO": handleAuthInfo,
				"XOVER":    handleXOVER,
				"ARTICLE":  handleArticle,
			},
		},
	}
}