- Timestamp:
- Aug 20, 2020, 6:05:01 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/downstream.go
r406 r409 851 851 delete(net.offlineClients, dc.clientName) 852 852 } 853 854 // Fast-forward history to last message 855 for target, history := range net.history { 856 if ch, ok := net.channels[target]; ok && ch.Detached { 857 continue 858 } 859 860 lastID, err := lastMsgID(net, target, time.Now()) 861 if err != nil { 862 dc.logger.Printf("failed to get last message ID: %v", err) 863 continue 864 } 865 history.clients[dc.clientName] = lastID 866 } 853 867 }) 854 868 … … 857 871 858 872 func (dc *downstreamConn) sendNetworkHistory(net *network) { 859 if dc.caps["draft/chathistory"] {873 if dc.caps["draft/chathistory"] || dc.srv.LogPath == "" { 860 874 return 861 875 } … … 865 879 } 866 880 867 seq, ok := history.clients[dc.clientName]881 lastDelivered, ok := history.clients[dc.clientName] 868 882 if !ok { 869 883 continue 870 884 } 871 history.clients[dc.clientName] = history.ring.Cur() 872 873 consumer := history.ring.NewConsumer(seq) 885 886 limit := 4000 887 history, err := loadHistoryLatestID(dc.network, target, lastDelivered, limit) 888 if err != nil { 889 dc.logger.Printf("failed to send implicit history for %q: %v", target, err) 890 continue 891 } 874 892 875 893 batchRef := "history" … … 882 900 } 883 901 884 for { 885 msg := consumer.Consume() 886 if msg == nil { 887 break 888 } 889 902 for _, msg := range history { 890 903 // Don't replay all messages, because that would mess up client 891 904 // state. For instance we just sent the list of users, sending … … 901 914 902 915 if dc.caps["batch"] { 903 msg = msg.Copy()904 916 msg.Tags["batch"] = irc.TagValue(batchRef) 905 917 } 906 907 918 dc.SendMessage(dc.marshalMessage(msg, net)) 908 919 } -
trunk/server.go
r398 r409 48 48 Hostname string 49 49 Logger Logger 50 RingCap int51 50 HistoryLimit int 52 51 LogPath string … … 65 64 return &Server{ 66 65 Logger: log.New(log.Writer(), "", log.LstdFlags), 67 RingCap: 4096,68 66 HistoryLimit: 1000, 69 67 users: make(map[string]*user), -
trunk/upstream.go
r407 r409 709 709 ch.Members[newNick] = memberships 710 710 uc.appendLog(ch.Name, msg) 711 uc.appendHistory(ch.Name, msg)712 711 } 713 712 } … … 819 818 820 819 uc.appendLog(ch.Name, msg) 821 uc.appendHistory(ch.Name, msg)822 820 } 823 821 } … … 1612 1610 } 1613 1611 1614 // TODO: handle moving logs when a network name changes, when support for this is added1615 1612 func (uc *upstreamConn) appendLog(entity string, msg *irc.Message) { 1616 1613 if uc.srv.LogPath == "" { … … 1624 1621 } 1625 1622 1626 if _, err := ml.Append(msg); err != nil {1627 uc.logger.Printf("failed to log message: %v", err)1628 }1629 }1630 1631 // appendHistory appends a message to the history. entity can be empty.1632 func (uc *upstreamConn) appendHistory(entity string, msg *irc.Message) {1633 1623 detached := false 1634 1624 if ch, ok := uc.network.channels[entity]; ok { … … 1638 1628 history, ok := uc.network.history[entity] 1639 1629 if !ok { 1630 lastID, err := lastMsgID(uc.network, entity, time.Now()) 1631 if err != nil { 1632 uc.logger.Printf("failed to log message: failed to get last message ID: %v", err) 1633 return 1634 } 1635 1640 1636 history = &networkHistory{ 1641 clients: make(map[string]uint64), 1642 ring: NewRing(uc.srv.RingCap), 1637 clients: make(map[string]string), 1643 1638 } 1644 1639 uc.network.history[entity] = history 1645 1640 1646 1641 for clientName, _ := range uc.network.offlineClients { 1647 history.clients[clientName] = 01642 history.clients[clientName] = lastID 1648 1643 } 1649 1644 … … 1652 1647 // clients too 1653 1648 uc.forEachDownstream(func(dc *downstreamConn) { 1654 history.clients[dc.clientName] = 0 1655 }) 1656 } 1657 } 1658 1659 history.ring.Produce(msg) 1649 history.clients[dc.clientName] = lastID 1650 }) 1651 } 1652 } 1653 1654 msgID, err := ml.Append(msg) 1655 if err != nil { 1656 uc.logger.Printf("failed to log message: %v", err) 1657 return 1658 } 1660 1659 1661 1660 if !detached { 1662 1661 uc.forEachDownstream(func(dc *downstreamConn) { 1663 history.clients[dc.clientName] = history.ring.Cur()1664 }) 1665 } 1666 } 1667 1668 // produce appends a message to the logs , adds it to the history and forwards1669 // it to connected downstreamconnections.1662 history.clients[dc.clientName] = msgID 1663 }) 1664 } 1665 } 1666 1667 // produce appends a message to the logs and forwards it to connected downstream 1668 // connections. 1670 1669 // 1671 1670 // If origin is not nil and origin doesn't support echo-message, the message is … … 1675 1674 uc.appendLog(target, msg) 1676 1675 } 1677 1678 uc.appendHistory(target, msg)1679 1676 1680 1677 // Don't forward messages if it's a detached channel -
trunk/user.go
r406 r409 52 52 53 53 type networkHistory struct { 54 clients map[string]uint64 // indexed by client name 55 ring *Ring // can be nil if there are no offline clients 54 clients map[string]string // indexed by client name 56 55 } 57 56
Note:
See TracChangeset
for help on using the changeset viewer.