Ejemplo n.º 1
0
// decodes an nntp message and writes it to a section of the file.
func decodeMsg(c *nntp.Conn, f *file, groups []string, MsgID string) {
	defer f.Done()
	g, err := findGroup(c, groups)
	if err != nil {
		putBroken(c)
		glog.Errorf("switching to group %s: %s", g, err)
		return
	}
	rc, err := c.GetMessage(MsgID)
	if err != nil {
		glog.Errorf("getting message %s from group %s: %s", MsgID, g, err)
		if _, ok := err.(*textproto.Error); ok {
			putConn(c)
		} else {
			putBroken(c)
		}
		return
	}
	putConn(c)

	yread, err := yenc.NewPart(bytes.NewReader(rc))
	if err != nil {
		glog.Errorln(err)
		return
	}
	wr := f.WriterAt(yread.Begin)
	_, err = io.Copy(wr, yread)
	if err != nil {
		glog.Errorln(err)
	}
}
Ejemplo n.º 2
0
func putBroken(c *nntp.Conn) {
	glog.Infof("%s Broken connection", c.ID)
	c.Close()
	connMu.Lock()
	connNum--
	connMu.Unlock()
}
Ejemplo n.º 3
0
func findGroup(c *nntp.Conn, groups []string) (string, error) {
	var err error
	for _, g := range groups {
		err = c.SwitchGroup(g)
		if err == nil {
			return g, nil
		}
	}
	return "", err
}
Ejemplo n.º 4
0
// check an nntp message exists.
func checkMsg(c *nntp.Conn, groups []string, MsgID string) {
	defer filewg.Done()
	g, err := findGroup(c, groups)
	if err != nil {
		putBroken(c)
		glog.Errorf("switching to group %s: %s", g, err)
		return
	}
	_, err = c.StatMessage(MsgID)
	if err != nil {
		glog.Errorf("getting message %s from group %s: %s", MsgID, g, err)
		if _, ok := err.(*textproto.Error); ok {
			putConn(c)
		} else {
			putBroken(c)
		}
		return
	}
	glog.Infof("%s has id %s", g, MsgID)
	putConn(c)
}