// 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) } }
func putBroken(c *nntp.Conn) { glog.Infof("%s Broken connection", c.ID) c.Close() connMu.Lock() connNum-- connMu.Unlock() }
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 }
// 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) }